<br><div class="gmail_quote">On Fri, Mar 18, 2011 at 4:33 PM, Jon Herman <span dir="ltr"><<a href="mailto:jfc.herman@gmail.com">jfc.herman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello all,<br><br>I am pretty new to Python and am trying to write data to a file. However, I seem to be misunderstanding how to do so. For starters, I'm not even sure where Python is looking for these files or storing them. The directories I have added to my PYTHONPATH variable (where I import modules from succesfully) does not appear to be it.<br>

<br>So my question is: How do I tell Python where to look for opening files, and where to store new files?<br><br>Thanks,<br><font color="#888888"><br>Jon<br>
</font><br></blockquote></div><br>By default Python will read and write files from the directory that your program is run from.  This cannot always be relied upon though (for instance if your program was imported as a module from another program).<br>
<br>To find out what directory your program is currently in use os.getcwd().  Here's an example I just ran...<br clear="all"><br>>>> import os<br>>>> os.getcwd()<br>'/media/DATA/code/lispy/liSpy'<br>
<br>The folder that is returned from os.getcwd() is the folder that "open" will use.  You can specify another folder by giving the full path.<br><br>open("/full/path/to/file.txt", "w")<br><br>
PYTHONPATH is for importing modules, which is a separate concern.<br><br>-- <br>Jack Trades<br><a href="http://pointlessprogramming.wordpress.com" target="_blank">Pointless Programming Blog</a><br><br>