Reputation: 1737
suppose I invoke a script thusly
python -m some_package.script
Is there a way to programmatically identify that __main__
belongs to some_package
?
Obviously I can't rely on __name__
because it's always the same value. I haven't figured out if I can rely on sys.argv[0]
because there might be an arbitrary number of directories before I get to a PYTHONPATH
variable.
Is there some way to discover the package to which a main script belongs?
Upvotes: 1
Views: 58