Use this to get the path of the current file. It will resolve any symlinks in the path.
import os
file_path = os.path.realpath(__file__)
This works fine on my mac. It won’t work from the Python interpreter (you need to be executing a Python file).
More Related Contents:
- How can I safely create a nested directory?
- Importing modules from parent folder
- Relative paths in Python
- Find full path of the Python interpreter?
- mkdir -p functionality in Python [duplicate]
- How do I get the path of the current executed file in Python?
- Expand Python Search Path to Other Source
- pip freeze creates some weird path instead of the package version
- Open file in a relative location in Python
- PyCharm current working directory
- Set up Python on Windows to not type “python” in cmd
- Python: Platform independent way to modify PATH environment variable
- Too many different Python versions on my system and causing problems
- Python list directory, subdirectory, and files
- How to configure Atom to run Python3 scripts?
- Why use sys.path.append(path) instead of sys.path.insert(1, path)?
- How can I troubleshoot Python “Could not find platform independent libraries “
- Unexpected python paths in conda environment
- Windows can’t find the file on subprocess.call()
- python subprocess Popen environment PATH?
- How to set working directory for projects in PyCharm?
- What is __path__ useful for?
- How can I safely create a directory (possibly including intermediate directories)?
- How do I use ‘~’ (tilde) in the context of paths?
- How can I extract the folder path from file path in Python?
- How to remove bad path characters in Python?
- How can I import files in Python using sys.path.append?
- Why not os.path.join use os.path.sep or os.sep?
- How to use to find files recursively?
- How do I import a Python script from a sibling directory?