Default path for writing a file (in PythonWin)

Carlos Ribeiro cribeiro at
Tue Feb 4 03:11:27 CET 2003

On Monday 03 February 2003 06:52 pm, dbrown2 at wrote:
> What should be the default path for myfile.write(mystring) if I use
> myfile = file('thefile','w')?  It looks like files are going to a
> library or package directory for me.  Is this a Python setting of
> PythonWin? Is there a way to change it?

I just use os.chdir in the top of my projects:

import os
os.chdir( <defaultdir> )

Of course, this code assumes that I know the path to the directory where your 
files will be located. If all you know is that you want your files to be 
located at the same directory where your script is located (or a location 
relative to that one, for instance), but you *don't* know where the actual 
script is (for example, the user simple copied the file to a different dir, 
and then started the script from the command line from a different 
directory)... it's still possible, but it may be a little more difficult; 
you'll probably need to check sys.argv[0], and then derive the path 
information from what you get here.

> Also, I have not been able to get a startup file to work in PythonWin.
>  I guess I need a specific description of where to place the startup
> file, what to name it, etc.

There is a script just for this - - that is optional, but it 
will be loaded automatically during the Python startup. Please check the 
documentation of the 'site' standard module in the standard Python docs; it 
will explain it in more detail, particularly how does it handle the path 

Carlos Ribeiro

More information about the Python-list mailing list