Profiling problem

Randall Hopper aa8vb at vislab.epa.gov
Fri May 7 12:12:33 EDT 1999


Why does the following example fail to resolve "self"?

(It's contrived, but it demonstrates my problem.)

I'd like to profile just a portion of a multi-module app, and after
browsing the profile section in libref and the "exec" description in
langref, I'm still not sure why this doesn't work.

Thanks,

Randall


>>> class C:
...    def slow_dog( self ):
...       import time
...       time.sleep(5)
...    def doit( self ):
...       import profile
...       profile.run( 'self.slow_dog()' )
... 
>>> c = C()
>>> c.doit()
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 7, in doit
  File "/home/rhh/software/python-1.5.2/lib/python1.5/profile.py", line 62, in run
    prof = prof.run(statement)
  File "/home/rhh/software/python-1.5.2/lib/python1.5/profile.py", line 348, in run
    return self.runctx(cmd, dict, dict)
  File "/home/rhh/software/python-1.5.2/lib/python1.5/profile.py", line 354, in runctx
    exec cmd in globals, locals
  File "<string>", line 1, in ?
NameError: self




More information about the Python-list mailing list