Reputation: 26
Is there a way to use the Open() function with an absolute path? I would like to open any file wherever it is on the disk, but Open() sets it's working directory to the location of the file by default, can I change this?
Upvotes: 0
Views: 346
Reputation: 442
If you are on linux you would need to add a /
to the beginning of the path, for example to access /tmp/someFile.txt
you would do open("/tmp/someFile.Txt")
. This works because / references the root.
On windows (this has not been tested) i before you would do open("C:/someFile.txt")
.
The docs for the open function can be found at: https://docs.python.org/3/library/functions.html#open
Upvotes: 1