Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'sys': 0.05; 'default:': 0.09; 'dict': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'def': 0.13; 'namespace.': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'then?': 0.16; 'wrote:': 0.16; 'maybe': 0.21; 'from:addr:web.de': 0.23; 'seconds': 0.25; 'pm,': 0.26; 'function': 0.27; 'skip:[ 10': 0.27; 'import': 0.27; 'pass': 0.28; 'example': 0.28; 'forgot': 0.28; 'skip:p 30': 0.29; '2005': 0.30; 'quite': 0.31; 'does': 0.32; 'to:addr:python-list': 0.33; 'right,': 0.34; 'calling': 0.34; 'header:X-Complaints-To:1': 0.34; 'skip:: 10': 0.36; 'but': 0.37; 'received:org': 0.37; 'skip:_ 10': 0.37; 'why': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; '1000': 0.62; 'you.': 0.64; 'believe': 0.65; 'works,': 0.68; 'profile': 0.73; '0.000': 0.84; '1001': 0.84; 'andrea': 0.84; 'dict,': 0.84; 'otten': 0.84; 'python2': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: importing and nose Date: Thu, 19 Jan 2012 19:09:52 +0100 Organization: None References: <4F184EAF.5080603@gmail.com> <4F1857C5.3040305@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084bab4.dip.t-dialin.net 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: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1326996608 news.xs4all.nl 6840 [2001:888:2000:d::a6]:42504 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19136 Andrea Crotti wrote: > On 01/19/2012 05:36 PM, Peter Otten wrote: >> >> I don't believe you. > > Quite sure it does: > > [andrea@precision test]$ cat simple.py > import profile > from os import path > import sys > > prof_path = path.join(path.dirname(__file__), 'profiling') > sys.path.append(prof_path) > import x > > > profile.run('x.f1()') > [andrea@precision test]$ cat simple.py > import profile > from os import path > import sys > > prof_path = path.join(path.dirname(__file__), 'profiling') > sys.path.append(prof_path) > import x > > > profile.run('x.f1()') > [andrea@precision test]$ python2 simple.py > 2005 function calls in 0.057 seconds > > Ordered by: standard name > > ncalls tottime percall cumtime percall filename:lineno(function) > 1001 0.007 0.000 0.007 0.000 :0(range) > 1 0.007 0.007 0.007 0.007 :0(setprofile) > 1 0.000 0.000 0.050 0.050 :1() > 1000 0.037 0.000 0.043 0.000 b.py:1(f2) > 0 0.000 0.000 profile:0(profiler) > 1 0.000 0.000 0.057 0.057 profile:0(x.f1()) > 1 0.007 0.007 0.050 0.050 x.py:4(f1) > > > > But in general you're perfectly right, I forgot about this profile > "issue", calling > profile.runctx('x.f1()', locals=locals(), globals=globals()) > works, even if maybe I don't even need to pass so much, but the x location > would be enough.. > > Why does the simple example works then? Because x is in __main__'s global namespace. And that is used as the default: def run(self, cmd): import __main__ dict = __main__.__dict__ return self.runctx(cmd, dict, dict)