Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8793 > unrolled thread

Re: Testing if a global is defined in a module

Started byChris Rebert <clp2@rebertia.com>
First post2011-07-04 14:03 -0700
Last post2011-07-04 14:03 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Testing if a global is defined in a module Chris Rebert <clp2@rebertia.com> - 2011-07-04 14:03 -0700

#8793 — Re: Testing if a global is defined in a module

FromChris Rebert <clp2@rebertia.com>
Date2011-07-04 14:03 -0700
SubjectRe: Testing if a global is defined in a module
Message-ID<mailman.607.1309813416.1164.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web