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


Groups > comp.lang.python > #8784

Testing if a global is defined in a module

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <tim@johnsons-web.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:module': 0.04; 'ubuntu': 0.04; 'classes.': 0.05; 'skip:` 10': 0.07; 'python': 0.08; 'integers': 0.09; 'received:64.4': 0.09; 'defined': 0.14; 'likewise': 0.16; 'res': 0.16; 'subject:global': 0.16; 'thru': 0.16; 'argument': 0.16; 'functions,': 0.19; 'appears': 0.21; 'here?': 0.23; 'variables': 0.29; 'object': 0.30; 'classes': 0.30; 'module': 0.30; 'iterating': 0.30; 'strings,': 0.30; 'thanks': 0.31; 'class': 0.31; 'values': 0.31; 'list': 0.32; 'to:addr :python-list': 0.34; 'header:User-Agent:1': 0.34; 'test': 0.34; 'example,': 0.35; 'none': 0.35; '2.6': 0.35; 'module.': 0.35; 'charset:us-ascii': 0.36; 'passed': 0.37; 'but': 0.37; 'members': 0.37; 'using': 0.37; 'something': 0.38; 'else': 0.38; 'returned': 0.39; 'to:addr:python.org': 0.39
Date Mon, 4 Jul 2011 10:11:33 -0800
From Tim Johnson <tim@johnsons-web.com>
To Python ML <python-list@python.org>
Subject Testing if a global is defined in a module
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
Organization AkWebsoft
User-Agent Mutt/1.5.20 (2009-06-14)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.603.1309803409.1164.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1309803409 news.xs4all.nl 21757 [2001:888:2000:d::a6]:60878
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8784

Show key headers only | View raw


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.

## A module has been imported, and we call `getmembers'
members = inspect.getmembers(mod)

## While iterating thru `members', we test to see
## if an object is defined in the module.
for m in members:
  obj = m[1]
  res = inspect.getmodule(obj)
## It appears that getmodule returns None for
## all but functions and classes.

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?
thanks
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Testing if a global is defined in a module Tim Johnson <tim@johnsons-web.com> - 2011-07-04 10:11 -0800
  Re: Testing if a global is defined in a module rantingrick <rantingrick@gmail.com> - 2011-07-04 12:40 -0700
    Re: Testing if a global is defined in a module Tim Johnson <tim@johnsons-web.com> - 2011-07-04 12:30 -0800
      Re: Testing if a global is defined in a module rantingrick <rantingrick@gmail.com> - 2011-07-04 14:30 -0700
        Re: Testing if a global is defined in a module Tim Johnson <tim@johnsons-web.com> - 2011-07-04 13:59 -0800
      Re: Testing if a global is defined in a module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-05 09:13 +1000
        Re: Testing if a global is defined in a module Tim Johnson <tim@johnsons-web.com> - 2011-07-04 15:26 -0800
          Re: Testing if a global is defined in a module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-05 09:33 +1000
            Re: Testing if a global is defined in a module Tim Johnson <tim@johnsons-web.com> - 2011-07-04 16:01 -0800
            Re: Testing if a global is defined in a module Chris Angelico <rosuav@gmail.com> - 2011-07-05 10:08 +1000
              Re: Testing if a global is defined in a module Grant Edwards <invalid@invalid.invalid> - 2011-07-05 14:11 +0000
                Re: Testing if a global is defined in a module "Waldek M." <wm@localhost.localdomain> - 2011-07-05 18:35 +0200
                Re: Testing if a global is defined in a module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-06 03:36 +1000
                Re: Testing if a global is defined in a module Chris Angelico <rosuav@gmail.com> - 2011-07-06 08:45 +1000
                Re: Testing if a global is defined in a module "Waldek M." <wm@localhost.localdomain> - 2011-07-06 08:00 +0200
                Re: Testing if a global is defined in a module Grant Edwards <invalid@invalid.invalid> - 2011-07-07 14:18 +0000
                Re: Testing if a global is defined in a module Chris Rebert <clp2@rebertia.com> - 2011-07-07 17:36 -0700
                Re: Testing if a global is defined in a module Grant Edwards <invalid@invalid.invalid> - 2011-07-05 22:39 +0000
            Re: Testing if a global is defined in a module Tim Johnson <tim@johnsons-web.com> - 2011-07-04 18:01 -0800
            Re: Testing if a global is defined in a module Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-04 22:28 -0600
            Re: Testing if a global is defined in a module Tim Johnson <tim@johnsons-web.com> - 2011-07-05 07:30 -0800
              Re: Testing if a global is defined in a module Grant Edwards <invalid@invalid.invalid> - 2011-07-05 15:43 +0000

csiph-web