The solution is to use __file__
and it’s pretty clean:
import os
TEST_FILENAME = os.path.join(os.path.dirname(__file__), 'test.txt')
More Related Contents:
- How to import a Python module from a sibling folder?
- What is __init__.py for?
- How to retrieve a module’s path?
- Generate random numbers with a given (numerical) distribution
- Reading file using relative path in python project
- What does a . in an import statement in Python mean?
- What’s the difference between a Python module and a Python package?
- Python 3: ImportError “No Module named Setuptools”
- Adding a module (Specifically pymorph) to Spyder (Python IDE)
- How to import a Python class that is in a directory above?
- How to refer to relative paths of resources when working with a code repository
- Defining private module functions in python
- Python – Module Not Found
- How does Python importing exactly work?
- ImportError after cython embed
- How to import a module in Python with importlib.import_module
- How to programmatically set a global (module) variable?
- Return a list of imported Python modules used in a script?
- Import a python module without running it
- How to compile a Python package to a dll
- ImportError: No module named six
- Homebrew + Python on mac os x 10.8: Fatal Python error: PyThreadState_Get: no current thread importing mapnik
- Where are the python modules stored?
- Module not found error in VS code despite the fact that I installed it
- Relative import in Python 3 is not working [duplicate]
- Flask(‘application’) versus Flask(__name__)
- How to install Tensorflow on Python 2.7 on Windows?
- Python modules with submodules and functions
- How to properly use relative or absolute imports in Python modules?
- Loading environment modules within a python script