Default path for files

Nobody nobody at nowhere.com
Sat Jan 30 11:01:19 EST 2010


On Sun, 24 Jan 2010 15:08:15 +0000, Rotwang wrote:

> Hi all, can anybody tell me whether there's a way to change the default
> location for files to be opened by open()? I'd like to be able to create
> files somewhere other than my Python folder without having to write the
> full path in the filename every time. Sorry if this is a stupid question,
> I don't know much about programming.

If you pass a relative pathname to open() (or any other function which
expects a filename), it will be interpreted relative to the current
directory.

Given that the current directory always seems to be the Python directory,
and you refer to it as a "folder", I'm guessing that you're running Python
on Windows via a shortcut in the Start Menu or on the desktop.

In which case, the ideal solution is probably to open the Properties
dialog for the shortcut and change the "Start in" field to your
"My Documents" directory (or some subdirectory of it).

Python itself won't care which directory it starts in.




More information about the Python-list mailing list