Well, yet another python question coming from me. This time it is to do with reading text files.
So when I use python using the IDLE interface I can find a file just by using:
file = open("filename.txt", r)
And that is fine. It hunts through the current directory and finds the file I ask for.
But then when I take exactly the same line of code it suddenly looks in the wrong directory. On Linux it looks in /home/“username”
So to try and get around that I used:
Thanks Lah, Your system worked perfectly.
HG1, yours looked for c:\Documents and settings\User\Desktop\
and so on. Which wasn’t particularly useful. Not to sure why it decided to have double slashes.
You can get an error when your folder is starting with an U. Eg. “C:\Users…”.
\U launches an eight-character Unicode escape sequence, eg. “\U00014321”.
You have to either duplicate or use a backslashes prefix r for the string (to generate a RAW string).
So you can write:
file = open (“C:\Users\Blender NEW\Game Files\Highscore.TXT”, “w”)
or so
file = open (r “C:\Users\Blender NEW\Data Files\Highscore.TXT”, “w”)