Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2328 > unrolled thread
| Started by | Vincent Ren <renws1990@gmail.com> |
|---|---|
| First post | 2011-03-31 18:48 -0700 |
| Last post | 2011-04-02 15:19 -0700 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
A problem about ipython Vincent Ren <renws1990@gmail.com> - 2011-03-31 18:48 -0700
Re: A problem about ipython Robert Kern <robert.kern@gmail.com> - 2011-04-01 10:16 -0500
Re: A problem about ipython Vincent Ren <renws1990@gmail.com> - 2011-04-02 15:19 -0700
| From | Vincent Ren <renws1990@gmail.com> |
|---|---|
| Date | 2011-03-31 18:48 -0700 |
| Subject | A problem about ipython |
| Message-ID | <43e40bbd-ae57-47dd-9e03-2d480278e4b6@j11g2000prn.googlegroups.com> |
Hey, everyone, I'm trying to use ipython recently. It's very nice,
however, when I run this(from Programming Python 3rd) in ipython, I'll
get a NameError:
In [1]: import settime, timer, set
In [2]: import profile
In [3]: profile.run('timer.test(100, settime.setops, set.Set)')
---------------------------------------------------------------------------
NameError Traceback (most recent call
last)
/home/vincent/hacking/python/<ipython console> in <module>()
/usr/lib/python2.6/profile.pyc in run(statement, filename, sort)
68 prof = Profile()
69 try:
---> 70 prof = prof.run(statement)
71 except SystemExit:
72 pass
/usr/lib/python2.6/profile.pyc in run(self, cmd)
454 import __main__
455 dict = __main__.__dict__
--> 456 return self.runctx(cmd, dict, dict)
457
458 def runctx(self, cmd, globals, locals):
/usr/lib/python2.6/profile.pyc in runctx(self, cmd, globals, locals)
460 sys.setprofile(self.dispatcher)
461 try:
--> 462 exec cmd in globals, locals
463 finally:
464 sys.setprofile(None)
/usr/lib/pymodules/python2.6/IPython/FakeModule.pyc in <module>()
NameError: name 'timer' is not defined
But when I use normal python shell, it works well
>>> import settime, timer, set
>>> import profile
>>> profile.run('timer.test(100, settime.setops, set.Set)')
^P^P 675906 function calls in 16.961 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall
filename:lineno(function)
118500 1.144 0.000 1.144 0.000 :0(append)
2 0.000 0.000 0.000 0.000 :0(clock)
500 0.008 0.000 0.008 0.000 :0(range)
1 0.004 0.004 0.004 0.004 :0(setprofile)
1 0.000 0.000 16.957 16.957 <string>:1(<module>)
0 0.000 0.000 profile:0(profiler)
1 0.000 0.000 16.961 16.961 profile:
0(timer.test(100, settime.setops, set.Set))
1500 0.380 0.000 2.504 0.002 set.py:13(union)
3400 0.076 0.000 2.632 0.001 set.py:2(__init__)
3400 1.620 0.000 2.556 0.001 set.py:20(concat)
544000 5.940 0.000 5.940 0.000 set.py:26(__getitem__)
1500 0.060 0.000 14.041 0.009 set.py:27(__and__)
1500 0.060 0.000 2.564 0.002 set.py:28(__or__)
1500 7.564 0.005 13.981 0.009 set.py:6(intersect)
100 0.100 0.001 16.953 0.170 settime.py:4(setops)
1 0.004 0.004 16.957 16.957 timer.py:1(test)
What's going wrong here?
Regards
Wenshan Ren
[toc] | [next] | [standalone]
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Date | 2011-04-01 10:16 -0500 |
| Message-ID | <mailman.78.1301671014.2990.python-list@python.org> |
| In reply to | #2328 |
On 3/31/11 8:48 PM, Vincent Ren wrote:
> Hey, everyone, I'm trying to use ipython recently. It's very nice,
> however, when I run this(from Programming Python 3rd) in ipython, I'll
> get a NameError:
>
>
> In [1]: import settime, timer, set
>
> In [2]: import profile
>
> In [3]: profile.run('timer.test(100, settime.setops, set.Set)')
> ---------------------------------------------------------------------------
> NameError Traceback (most recent call
> last)
>
> /home/vincent/hacking/python/<ipython console> in<module>()
>
> /usr/lib/python2.6/profile.pyc in run(statement, filename, sort)
> 68 prof = Profile()
> 69 try:
> ---> 70 prof = prof.run(statement)
> 71 except SystemExit:
> 72 pass
>
> /usr/lib/python2.6/profile.pyc in run(self, cmd)
> 454 import __main__
> 455 dict = __main__.__dict__
> --> 456 return self.runctx(cmd, dict, dict)
> 457
> 458 def runctx(self, cmd, globals, locals):
>
> /usr/lib/python2.6/profile.pyc in runctx(self, cmd, globals, locals)
> 460 sys.setprofile(self.dispatcher)
> 461 try:
> --> 462 exec cmd in globals, locals
> 463 finally:
> 464 sys.setprofile(None)
>
> /usr/lib/pymodules/python2.6/IPython/FakeModule.pyc in<module>()
>
> NameError: name 'timer' is not defined
In order to support pickling and its %run feature, IPython makes a fake __main__
module. It looks like profile.run() explicitly imports __main__ to try to run
the statement there. Honestly, it's been a thorn in our side for a long time,
but it's a confusing bit of the code. Most interactive shells actually written
in Python are going to have a similar need to do a workaround, since they
already have a __main__. The regular shell is not written in Python, so it has
no problem.
You will want to ask on the IPython list for future IPython questions.
http://mail.scipy.org/mailman/listinfo/ipython-user
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
[toc] | [prev] | [next] | [standalone]
| From | Vincent Ren <renws1990@gmail.com> |
|---|---|
| Date | 2011-04-02 15:19 -0700 |
| Message-ID | <8094d34d-57f4-4564-a647-c26aaab0f13c@r35g2000prj.googlegroups.com> |
| In reply to | #2361 |
On Apr 2, 1:16 am, Robert Kern <robert.k...@gmail.com> wrote: > > In order to support pickling and its %run feature, IPython makes a fake __main__ > module. It looks like profile.run() explicitly imports __main__ to try to run > the statement there. Honestly, it's been a thorn in our side for a long time, > but it's a confusing bit of the code. Most interactive shells actually written > in Python are going to have a similar need to do a workaround, since they > already have a __main__. The regular shell is not written in Python, so it has > no problem. > > You will want to ask on the IPython list for future IPython questions. > > http://mail.scipy.org/mailman/listinfo/ipython-user > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > that is made terrible by our own mad attempt to interpret it as though it had > an underlying truth." > -- Umberto Eco Quite nice explanation and very useful link, thanks :)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web