Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:module': 0.04; 'convention,': 0.09; 'globals': 0.09; 'received:64.4': 0.09; 'defined': 0.14; 'wrote:': 0.15; '"""check': 0.16; 'crew': 0.16; 'naming': 0.16; 'okay,': 0.16; 'rantingrick': 0.16; 'subject:global': 0.16; 'argument': 0.16; 'def': 0.16; 'source.': 0.19; 'pointed': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'code': 0.24; 'modules': 0.25; "i'm": 0.27; 'import': 0.29; 'second': 0.29; 'object': 0.30; 'skip:( 20': 0.30; 'module': 0.30; 'imported': 0.30; 'thanks': 0.31; 'earlier': 0.32; 'to:addr :python-list': 0.34; 'header:User-Agent:1': 0.34; 'test': 0.34; 'like:': 0.35; 'module.': 0.35; '(not': 0.35; 'probably': 0.35; 'johnson': 0.35; 'some': 0.37; 'subject:: ': 0.38; 'something': 0.38; 'think': 0.38; 'should': 0.39; 'processing': 0.39; 'to:addr:python.org': 0.39; 'target': 0.61; 'making': 0.66; 'show': 0.67; 'with,': 0.77; 'distinguish': 0.84; 'regexps': 0.84 Date: Mon, 4 Jul 2011 13:59:13 -0800 From: Tim Johnson To: python-list@python.org Subject: Re: Testing if a global is defined in a module References: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1309816628 news.xs4all.nl 21869 [2001:888:2000:d::a6]:56144 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8797 * rantingrick [110704 13:47]: > On Jul 4, 3:30 pm, Tim Johnson wrote: > > > >   Thanks for the reply: *but* > >   dir() 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 > > 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