Created
February 24, 2017 21:09
-
-
Save meilinger/5e2212e58d476de2734d1c16ba02092b to your computer and use it in GitHub Desktop.
Python `open` files relative to executing script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In order open a file relative to the executing script path (vs relative to the working directory of the python interpreter) | |
# use: | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment