Relative paths in Python - Stack Overflow
https://stackoverflow.com/questions/91815426.05.2009 · dirname = os.path.dirname(__file__) filename = os.path.join(dirname, 'relative/path/to/file/you/want') This will give you the absolute path to the file you're looking for. Note that if you're using setuptools, you should probably use its package resources APIinstead. UPDATE: I'm responding to a comment here so I can paste a code sample.
Relative paths in Python - Stack Overflow
stackoverflow.com › questions › 918154May 27, 2009 · First, define the tool function named relpath, which convert a relative path to current file into a relative path to cwd. import os relpath = lambda p: os.path.normpath(os.path.join(os.path.dirname(__file__), p)) Then we use it to wrap paths which is relative to current file. path1 = relpath('../src/main.py')
Relative Path in Python - Delft Stack
www.delftstack.com › howto › pythonRelative path means the path of a certain file relative to the current working directory. For example, if the current working directory is C:\PythonProjects\Tutorials , the path.py file’s relative path would be \Paths\paths.py which is shorter and easier to use than the absolute path C:\PythonProjects\Tutorials\Paths\paths.py .