CWD + relative path + import name == resultant relative path?

Dieter Maurer dieter at handshake.de
Sat Oct 30 13:57:47 EDT 2021


Dan Stromberg wrote at 2021-10-29 16:38 -0700:
>Is there a predefined function somewhere that can accept the 3 things on
>the LHS in the subject line, and give back a resultant relative path -
>relative to the unchanged CWD?
>
>To illustrate, imagine:
>1) You're sitting in /home/foo/coolprog
>2) You look up the AST for /home/foo/coolprog/a/b/c.py
>3) /home/foo/coolprog/a/b/c.py has a relative import of ..blah

Look at the functions provided by `os.path`.

Maybe, you do not need relative path: look at `importlib`
(which also supports import via absolute paths).


More information about the Python-list mailing list