How to write a whole string to a file in Python and where does the file go?
Question: I am doing an assignment on text formatting and alignment (text wrapping) and
I need to write my formatted string to new file. But once I have written to
the file (or think I've written) where does that file go? Does it actually
create a file on my desktop or am I being stupid?

This is my code:

    
    
    txtFile = open("Output.txt", "w")
    txtFile.write(string)
    txtFile.close()
    
    return txtFile
    

Cheers,

JT


Answer: The text is written to a file called "Output.txt" in your working directory
(which is usually the directory from which the script has been executed).

To display the working directory, you can use:

    
    
    >>> import os
    >>> os.getcwd()
    '/home/adam'
    

