I've searched and this seems to be a simple question without a simple answer.
I have the file a/b/c.py
which would be called with python -m a.b.c
. I would like to obtain the value a.b.c
in the module level.
USAGE = u'''
Usage:
python -m %s -h
''' % (what_do_i_put_here,)
So when I receive the -h
option, I display the USAGE
without the need to actually write down the actual value in each and every script.
Do I really need to go through inspect
to get the desired value?
Thanks.
EDIT: As said, there are answers (I've searched), but not simple answers. Either use inspect
, use of traceback
, or manipulate __file__
and __package__
and do some substring to get the answer. But nothing as simple as if I had a class in the module, I could just use myClass.__module__
and I would get the answer I want. The use of __name__
is (unfortunately) useless as it's always __main__
.
Also, this is in python 2.6 and I cannot use any other versions.
question from:
https://stackoverflow.com/questions/5183601/how-to-get-the-current-running-module-path-name 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…