Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'subject:module': 0.04; 'python': 0.08; 'globals': 0.09; 'received:64.4': 0.09; 'defined': 0.14; 'wrote:': 0.15; 'rantingrick': 0.16; 'subject:global': 0.16; '>>>': 0.16; 'variable': 0.21; 'header:In-Reply-To:1': 0.22; 'modules': 0.25; 'skip:[ 10': 0.26; '(and': 0.27; 'import': 0.29; 'module': 0.30; 'imported': 0.30; 'thanks': 0.31; 'print': 0.32; "skip:' 10": 0.32; 'to:addr:python-list': 0.34; 'header:User- Agent:1': 0.34; 'module.': 0.35; 'johnson': 0.35; 'accepted': 0.36; 'subject:: ': 0.38; 'data': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'target': 0.61; 'show': 0.67; 'trial': 0.69; 'distinguish': 0.84; 'exercise.': 0.84 Date: Mon, 4 Jul 2011 12:30:39 -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: <3dc7e7a8-9a90-499a-b544-bb9969d9ab55@t5g2000yqj.googlegroups.com> 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1309811314 news.xs4all.nl 21762 [2001:888:2000:d::a6]:41746 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8792 * rantingrick [110704 12:00]: > On Jul 4, 1:11 pm, Tim Johnson wrote: > > Well if you follow the python style guide (and most accepted styles > for global notation) then it's a trial exercise. You don't even have > to import anything!!! :) > > >>> GLOBAL_STR = 'str' > >>> GLOBAL_FLOAT = 1.33333 > >>> GLoBaL_Bs = '' > >>> dir() > ['GLOBAL_FLOAT', 'GLOBAL_STR', 'GLoBaL_Bs', '__builtins__', '__doc__', > '__name__', '__package__', 'item'] > >>> for item in dir(): > if item.isupper(): > print 'Found Global!', item 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 print(dir(targetmodule)) => ['Install', 'TestAddresses', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'chmod', 'consoleMessage', 'cp', 'debug', 'erh', 'exists', 'halt', 'is_list', 'load', 'makePath', 'mkdir', 'process', 'sys', 'traceback', 'usingCgi'] where 'TestAddresses' is a member of an imported module and 'usingCgi' is the only data variable defined in regards -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com