[Tutor] Verifying My Troublesome Linkage Claim between Python and Win7

Steven D'Aprano steve at pearwood.info
Sat Feb 27 19:58:19 CET 2010

On Sun, 28 Feb 2010 05:30:49 am Wayne Watson wrote:
> Ok, I'm back after a three day trip. You are correct about the use of
> pronouns and a few misplaced words. I should have reread what I
> wrote. I had described this in better detail elsewhere, and followed
> that description with the request here probably thinking back to it. 
> I think I was getting a bit weary of trying to find an answer. Try
> t;his.
> Folder1
>     track1.py
>    data1.txt
>    data2.txt
>    data3.txt
> Folder2
>     track1.py
>     dset1.txt
>     dset2.txt
>     ...
>     dset8.txt
> data and dset files have the same record formats. track1.py was
> copied into  Folder2 with ctrl-c + ctrl-v. When I run track1.py from
> folder1, it clearly has examined the data.txt  files. If I run the
> copy of track1.py in folder2, it clearly operates on folder1 (one)
> data.txt files. This should not be.

Without seeing the code in track1.py, we cannot judge whether it should 
be or not. I can think of lots of reasons why it should be. For 

if you have hard-coded the path to Folder1

if you call os.chdir(Folder1)

if you have changed the PATH so that Folder1 gets searched before the 
current directory

then the behaviour you describe theoretically could happen.

How are you calling track1.py? Do you do this?

  cd Folder2
  python track1.py 

What if you change the second line to:

  python ./track1.py

Are you perhaps using this?

  python -m track1

If you change the name of the copy from track1.py to copy_of_track1.py, 
and then call this:

  python copy_of_track1.py 

how does the behaviour change?

> If I look at  the  properties of track1.py in folder2  (two), it  is
> pointing back to the program in folder1 (one).

What? "Pointing back", as in a Shortcut? Or a symlink?

If you've created a shortcut instead of a copy, I'm not surprised you 
are executing it in the "wrong" folder. That's what shortcuts do.

Steven D'Aprano

More information about the Tutor mailing list