Try:
f = open('Desktop/temp/myfile.txt', 'r')
This will open the file relative to the current directory. You can use '/Desktop/temp/myfile.txt' if you want to open the file using an absolute path. The second parameter to open the function is the mode (I donβt know what file1 should mean in your example).
And in relation to the question - Python follows the OS scheme - it looks in the current directory, and if it searches for modules, it looks in sys.path after. And if you want to open the file from some subdirectory, use os.path.join, for example:
import os f = open(os.path.join('Desktop', 'temp', 'myfile.txt'), 'r')
Then you will be safe from clutter with '/' and '\'.
And see the docs for the built-in open function for more information on how to use the open function.
Abgan source share