How to find the package a module belongs to ?
Jeff Sandys
sandysj at asme.org
Fri Jun 1 15:48:23 EDT 2001
I don't fully understand your question, could you give
a code sample and show how it fails your expectation.
Sasa Zivkov wrote:
>
> I have a package containing several modules.
> Is is possible, within a module,
> to say "give me the package I belong to" ?
>
We use a global variable in each module like this:
modname="mymodule"
And each function has a function name variable like this:
def myfunction():
ftn="myfunction"
Then we can use the module and function name for debug and fatal errors:
def debug(ftn,txt):
sys.stdout.write(string.join([modname,'.',ftn,':',txt,'\n'],''))
sys.stdout.flush()
def fatal(ftn,txt):
msg=string.join([modname,'.',ftn,':FATAL:',txt,'\n'],'')
raise SystemExit, msg
> Or, is there a way to access objects defined in __init__.py from
> a module without explicitly referencing surounding package by name ?
>
> -- Sasa
I think this is our solution to the problem that you raise.
It would sure be nice to pull this information from some
secret variable without having to explicitly name them.
Thanks,
Jeff Sandys
More information about the Python-list
mailing list