Created
November 11, 2021 01:48
-
-
Save luochen1990/9b1ffa30f5c4a721dab5991e040e3eb1 to your computer and use it in GitHub Desktop.
Path relative to current file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import os | |
relpath = lambda p: os.path.normpath(os.path.join(os.path.dirname(__file__), p)) | |
sys.path.append(relpath('..')) # so that you can import from upper dir | |
path1 = relpath('../src/main.py') | |
print(f'path1 relative to cwd: {path1}') | |
print(f'path1 absolute path: ({ os.path.abspath(path1) })') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment