Default path for files

Christian Heimes lists at cheimes.de
Sun Jan 24 11:01:27 EST 2010


Rotwang wrote:
> import os
> os.chdir(<path>)
> 
> to site.py (or any other module which is automatically imported during 
> initialisation) change the default location to <path> every time I used 
> Python?

First of all you shouldn't alter the site module ever! The optional
sitecustomize module exists to make global changes.

A library must never change the current working directory. It's up to
the application to choose the right working directory. If you mess with
the working directory in a library or global module like site you *will*
break applications. Python has multiple ways to modify the list of
importable locations, either globally, for the current user or the
current application. Use them wisely!

Christian




More information about the Python-list mailing list