Answers for "python open file absolute path"

2

python get absolute path of file

>>> import os
>>> os.path.abspath("mydir/myfile.txt")
'C:/example/cwd/mydir/myfile.txt'
Posted by: Guest on June-02-2021
1

python open file relative to script location

import os

path = 'a/relative/file/path/to/this/script/file.txt'

with open(os.path.join(os.path.dirname(__file__), path), 'r') as input_file:
    content = input_file.read()
Posted by: Guest on August-31-2020

Python Answers by Framework

Browse Popular Code Answers by Language