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

Dan Stromberg drsalists at gmail.com
Fri Oct 29 19:38:09 EDT 2021


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

Is there something preexisting that can figure out what path blah is
supposed to have, assuming 100% pure python code?

Or is it necessary to actually import to get that?  I think I could import
and then check __file__, but I'd rather avoid that if possible.

Thanks!


More information about the Python-list mailing list