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


Groups > comp.lang.python > #8797

Re: Testing if a global is defined in a module

Date 2011-07-04 13:59 -0800
From Tim Johnson <tim@johnsons-web.com>
Subject Re: Testing if a global is defined in a module
References <mailman.603.1309803409.1164.python-list@python.org> <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> <mailman.606.1309811314.1164.python-list@python.org> <d2e317cc-1f48-4636-b888-0d661c081b2e@k16g2000yqm.googlegroups.com>
Organization AkWebsoft
Newsgroups comp.lang.python
Message-ID <mailman.610.1309816628.1164.python-list@python.org> (permalink)

Show all headers | View raw


* rantingrick <rantingrick@gmail.com> [110704 13:47]:
> On Jul 4, 3:30 pm, Tim Johnson <t...@johnsons-web.com> wrote:
> >
> >   Thanks for the reply: *but*
> >   dir(<targetmodule>) will also show globals from other modules imported
> >   by the target module. So I would need a way to distinguish between
> >   those imported and those defined in <targetmodule>
> 
> Okay, then do some processing on the source. You can use regexps or
> the module mentioned earlier by Chris.
  I think I'm making this unnecessarily complicated. I had used
  something like:

  from spam import TestAddresses ## just for grins

  Which is something that I almost never do in practice.

  Also, you pointed out the UC naming convention, which I was
  unacquainted with, being self-employed, self-taught and a one-man
  crew who doesn't spend as much time as he should reading PEPs.

  I'm going to go for the predicate test as second argument to
  getmembers with something like:
def isdata(self,obj,name):
    """Check if an object is of a type that probably means it's data."""
    return (not (inspect.ismodule(obj) or inspect.isclass(obj) or
                inspect.isroutine(obj) or inspect.isframe(obj) or
                inspect.istraceback(obj) or inspect.iscode(obj)))
                and name.issupper()
## Untested code

thanks again
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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