>>> import os
>>> os.path.abspath("mydir/myfile.txt")
'C:/example/cwd/mydir/myfile.txt'
Also works if it is already an absolute path:
>>> import os
>>> os.path.abspath("C:/example/cwd/mydir/myfile.txt")
'C:/example/cwd/mydir/myfile.txt'
More Related Contents:
- Relative paths in Python
- How to refer to relative paths of resources when working with a code repository
- Open file in a relative location in Python
- constructing absolute path with os.path.join()
- 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
- How do I get the path of the current executed file in Python?
- Reading file using relative path in python project
- How do I get the path of the Python script I am running in? [duplicate]
- Expand Python Search Path to Other Source
- 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
- Slash (/) vs tilde slash (~/) in style sheet path
- 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)?
- 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 can I safely create a directory (possibly including intermediate directories)?
- Get absolute paths of all files in a directory
- Python: is the current directory automatically included in path?
- How do I use ‘~’ (tilde) in the context of paths?
- Changing the directory where .pyc files are created
- Python not able to open file with non-english characters in path
- How do I import a Python script from a sibling directory?