[Zope] Cautionary tale -- OSError: [Errno 2] No such file or directory

Passin, Tom tpassin@mitretek.org
Fri, 4 Apr 2003 12:05:20 -0500


[ John Ziniti]
>=20
> It then dawned on me that we do a lot of "os.chdir()" in our Products
> to make sure we are in a directory we can write in.  We also have
> at least one Product that deletes it's working directory=20
> after it is done.

I think you should **never** change or depend on the current working
directory, and you have jsut showed why.  Instead, your code modules can
discover their own directory, and you can use relative paths from that.

This works very well for external methods - if you put their code into a
package so that __file__ can return something -- and it should be
possible for products as well.  When you arrane things like this, you
never have to cd and then retstore the right directory, and you can
always be sure your code can find and write the files it needs.

Cheers,

Tom P