Answers for "how to give file path in python"

1

python file location path

import os

print('getcwd:      ', os.getcwd())
print('__file__:    ', __file__)
Posted by: Guest on August-23-2020
1

python make file path os

import os

FilePath = os.path.join("Folder","File.txt")
Posted by: Guest on August-13-2021
1

python how to open a file in a different directory in mac

import os
f = open (os.path.expanduser("~/Desktop/somedir/somefile.txt"))
Posted by: Guest on August-16-2020
0

windows how to store filepath as variabley python

from pathlib import Path

docs_folder = Path("some_folder/some_folder/")
text_file = docs_folder / "some_file.txt"
f = open(text_file)

#note must use forward slashes as pathlib will convert these to \ for windows
Posted by: Guest on October-03-2020

Code answers related to "how to give file path in python"

Python Answers by Framework

Browse Popular Code Answers by Language