Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19136 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2012-01-19 19:09 +0100 |
| Last post | 2012-01-19 19:09 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: importing and nose Peter Otten <__peter__@web.de> - 2012-01-19 19:09 +0100
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2012-01-19 19:09 +0100 |
| Subject | Re: importing and nose |
| Message-ID | <mailman.4870.1326996608.27778.python-list@python.org> |
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 <string>:1(<module>)
> 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)
Back to top | Article view | comp.lang.python
csiph-web