inspect.getmodulename giving unexpected results
Geoff Bache
geoff.bache at gmail.com
Fri Sep 24 11:03:20 EDT 2010
> > Unfortunately, it doesn't seem to do that in some cases. Consider the
> > following code:
>
> It does behave as documented: it does not find package names, or investigate
> sys.modules
Possibly, although for me "logging" is exposed as a module, and ought
to behave as one when requesting the module name. The fact that it's a
package internally doesn't seem relevant to me in this context. It's
weird to me that when I do
import os, logging
treating these things as normal modules I can get the right name for
"os" but get "__init__" when requesting "logging". Externally, these
things appear to be the same. I can accept from the docs that if I did
"getmodulename" on "logging.config" I would get "config" back.
>
> > ## file 'inspect_test'
>
> rename this file to "inspect_test.py", and the filename will make sense to
> inspect.getmodulename, which should *then* return "inspect_test" instead of
> None.
I realise that, but of course I can't do that in the real code. It's a
long-established convention to drop the ".py" from executable programs
on UNIX.
Regards,
Geoff
More information about the Python-list
mailing list