RE: [Zope] Cautionary tale -- OSError: [Errno 2] No such file or directory
[ John Ziniti]
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 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
Passin, Tom wrote:
I think you should **never** change or depend on the current working directory, [snip]
Cheers,
Tom P
I _totally_ agree, in principal, but ... In my specific situation, the external method launches another program from a third party which breaks if the cwd is not correct. I don't like it but have to deal with it until the legacy crud is gone (which I'm working on.) The posts in this thread were very healpful to me, thanks to all who contributed. sbb
On Friday 04 April 2003 7:32 pm, Scott Burchill wrote:
I _totally_ agree, in principal, but ...
In my specific situation, the external method launches another program from a third party which breaks if the cwd is not correct. I don't like it but have to deal with it until the legacy crud is gone (which I'm working on.)
If this is on Unix then the right approach is to fork, chdir in the child, then exec. If this is windows, or you dont want to get into unixness, the no-brainer approach is to write a temporary wrapper script or batch file that changes directory then runs the real process. -- Toby Dickenson http://www.geminidataloggers.com/people/tdickenson
participants (3)
-
Passin, Tom -
Scott Burchill -
Toby Dickenson