Try to use a filename relative to the current files path. Example for ‘./my_file’:
fn = os.path.join(os.path.dirname(__file__), 'my_file')
In Python 3.4+ you can also use pathlib:
fn = pathlib.Path(__file__).parent / 'my_file'
More Related Contents:
- Relative paths in Python
- How to get an absolute file path in Python
- Open file in a relative location in Python
- How can I import files in Python using sys.path.append?
- How can I safely create a nested directory?
- Relative imports for the billionth time
- mkdir -p functionality in Python [duplicate]
- How do I get the path of the current executed file in Python?
- Reading file using relative path in python project
- Expand Python Search Path to Other Source
- Test if executable exists in Python?
- Importing from a relative path in Python
- PyCharm current working directory
- How can I find where Python is installed on Windows?
- Python list directory, subdirectory, and files
- How to configure Atom to run Python3 scripts?
- mixed slashes with os.path.join on windows
- Why use sys.path.append(path) instead of sys.path.insert(1, path)?
- Keras import error Nadam
- Unexpected python paths in conda environment
- Windows can’t find the file on subprocess.call()
- How to set working directory for projects in PyCharm?
- What is __path__ useful for?
- How should I write a Windows path in a Python string literal?
- How can I safely create a directory (possibly including intermediate directories)?
- Python: is the current directory automatically included in path?
- How do I use ‘~’ (tilde) in the context of paths?
- Cannot find the file specified when using subprocess.call(‘dir’, shell=True) in Python
- Finding all paths/walks of given length in a networkx graph
- Use wildcard with os.path.isfile()