executing python scripts that are symlinked

Charles Smith cts.private.yahoo at gmail.com
Thu May 16 05:23:35 EDT 2013


On 16 Mai, 11:04, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> Python does use your current working directory as your current working
> directory. I think you are misdiagnosing the problem.


That's usually how it ends up ...



>
> Here's a demonstration:
>
> steve at runes:~$ cat test.py
> import os
> print os.getcwd()
>
> steve at runes:~$ ln -s ~/test.py /tmp/test
> steve at runes:~$ ls -l /tmp/test
> lrwxrwxrwx 1 steve steve 19 May 16 18:58 /tmp/test -> /home/steve/test.py
> steve at runes:~$ cd /etc/
> steve at runes:/etc$ python /tmp/test
> /etc


You're right.  I can believe that python doesn't really change it's
notion of the CWD.

It seems like when I'm in WC and invoke ./script (which is symlinked
to H/script), python says, "I have a specification somewhere that says
I can look for modules where my script is, and since I'm really smart,
I happen to know that I'm in WC but the script is not, but is really
in H, where the stupid operator better have his packages set up"


>
> > I have a python script that works fine when it sits in directory WC, but
> > if I move it out of WC to H and put a symlink from H/script to WC, it
> > doesn't find the packages that are in WC.  Also, if I use the absolute
> > path to H, it won't find them, but I guess I can understand that.
>
> The obvious solution is to make sure that WC is in the Python path.
...

> but that's a crappy solution,

Right.  Other tools don't try to figure out what I really want to do
with a symlink, but just accept that it's a file.  Python should do
the same ...

But, as you say, I'm surely misdiagnosing the problem.




More information about the Python-list mailing list