My claim is that if one creates a program in a folder that reads a file
in the folder it and then copies it to another folder, it will read the
data file in the first folder, and not a changed file in the new folder.
I'd appreciate it if some w7 users could try this, and let me know what
they find.
My experience is that if one checks the properties of the copied file,
it will point to the original py file and execute it and not the copy.
# Test program. Examine strange link in Python under Win7
# when copying py file to another folder.
# Call the program vefifywin7.py
# To verify my situation use IDLE, save and run this program there.
# Put this program into a folder along with a data file
# called verify.txt. Create a single text line with a few characters in it
# Run this program and note if the output
# Copy the program and txt file to another folder
# Change the contents of the txt file
# Run it again, and see if the output is the same as in the other folder
track_file = open("verify.txt")
aline = track_file.readline();
print aline
track_file.close()
I am a mere hobbyist programmer, but I think real programmers will
tell you that it is a bad habit to use relative paths. Use absolute
paths instead and remove all doubt.
http://docs.python.org/library/os.path.html
RD
It isn't useful to respond to a serious question with OS bigotry.
How do you invoke the program? Do you use a Command Prompt window?
I don't know what you mean by "300 lines". Have you opened a Command Prompt
window, changed to the directory where you copied the files, and executed:
python your_prog.py
?
I've no time to verify your specific claim and have no readily available
proof for mine, but I've seen similar issues on Win7. AFAIK, this has
nothing to do with Python.
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/
"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer
> It isn't useful to respond to a serious question with OS bigotry.
Interesting about 'similar'. I'm pretty much done exploring every nook
and cranny on this problem. It can be worked around. I will say that if
I look at the properties of the copied file, it shows a shortcut tab
that leads back to the original file. I have no recollection of making a
shortcut, and always use Copy and Paste. Further, if I do create
shortcut in W7, it adds "-shortcut to the file suffix. I do not ever
recall seeing that anywhere. I just tried it in XP, and it puts it in
front of the name.
On a fresh install of Win7 Ultimate, I created your program & the text
file in one folder, then copied the program both using ctrl-c/ctrl-v
and later ctrl-drag-&-drop. In both cases, the copied program *did
not* refer to the text file when executed:
D:\projects>a
Traceback (most recent call last):
File "D:\projects\a.py", line 1, in <module>
track_file = open("verify.txt")
IOError: [Errno 2] No such file or directory: 'verify.txt'
Whatever you seem to think you did, you didn't, or you're not
providing enough detail on what you did to repeat the behaviour.
I do agree with the sentiment that this isn't a Python issue.