Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8793
| References | <20110704181133.GH1971@johnsons-web.com> |
|---|---|
| Date | 2011-07-04 14:03 -0700 |
| Subject | Re: Testing if a global is defined in a module |
| From | Chris Rebert <clp2@rebertia.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.607.1309813416.1164.python-list@python.org> (permalink) |
On Mon, Jul 4, 2011 at 11:11 AM, Tim Johnson <tim@johnsons-web.com> wrote: > Using Python 2.6 on ubuntu 10.04. > inspect module : > I want to 'inspect' a module and get a list of all > functions, classes and global variables in that module. You meant "first defined in" that module. <snip> > Example, for a module name `mvcInstall', when a class > name `Install' that is defined in the module > is passed as an argument to inspect.getmodule, the > values returned is something like > "<module 'mvcInstall' from > '/home/tim/prj/cgi/libraries/python/mvcInstall.py'>" > Likewise for functions defined in the module. > > ** But ** when global variables such as strings, booleans, > integers are passed as an argument to getmodule, the > value returned is `None'. > > What else can I do here? Look at the names in the module's import statements using the `ast` module, and exclude those from the set of names defined in the module. Won't work for `from foo import *`, but that's bad practice and should be refactored anyway. Cheers, Chris -- http://rebertia.com
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Testing if a global is defined in a module Chris Rebert <clp2@rebertia.com> - 2011-07-04 14:03 -0700
csiph-web