You can use os.path
and its functions, which take care of OS-specific paths:
>>> import os
>>> os.path.join('app', 'subdir', 'dir', 'filename.foo')
'app/subdir/dir/filename.foo'
On Windows, it should print out with backslashes.
More Related Contents:
- Python: Platform independent way to modify PATH environment variable
- How can I safely create a nested directory?
- Windows path in Python
- Importing modules from parent folder
- Python: What OS am I running on?
- How to get an absolute file path in Python
- Find full path of the Python interpreter?
- os.makedirs doesn’t understand “~” in my path
- Why am I getting a FileNotFoundError?
- pip freeze creates some weird path instead of the package version
- Python pip install module is not found. How to link python to pip location?
- Open file in a relative location in Python
- Monitoring contents of files/directories? [duplicate]
- Why doesn’t os.path.join() work in this case?
- Set up Python on Windows to not type “python” in cmd
- How to identify on which OS Python is running on?
- Too many different Python versions on my system and causing problems
- What is a cross-platform way to get the home directory?
- Possible values from sys.platform?
- Cross-platform subprocess with hidden window
- How can I troubleshoot Python “Could not find platform independent libraries “
- How do I read an image from a path with Unicode characters?
- Regular Expression to match cross platform newline characters
- Import from sibling directory
- Python: import module from another directory at the same level in project hierarchy
- python subprocess Popen environment PATH?
- Why does the calculated width and height in pixel of a string in Tkinter differ between platforms?
- 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()