In my Python books and also the Python Documents this code should be enough to open a file:
f = open("file.txt", "r")
But if I do this I will get an error message telling me file.txt doesn’t exist. If I however use the whole path where file.txt is located it opens it:
f = open("C:/Users/Me/Python/file.txt", "r")
Is there an explanation for this?
In short – the immediate search path (the current working directory) is where Python will look… (so on Windows – possibly it’ll assume C:\Pythonxy)
Yes, it depends on where Python/IDLE is executed… for it to use its search path:
And in a shell – changing directories… then launching Python/IDLE