[Tutor] import problem
Lee Cullens
leec03273 at mac.com
Tue Apr 19 08:32:37 CEST 2005
I assume you mean PythonIDE for Python 2.3 (I usually use 2.4 and
WingIDE). Here it is (indents screwed up with var font):
HTH,
Lee C
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)]
Type "copyright", "credits" or "license" for more information.
MacPython IDE 1.0.1
>>> import timeit
>>> def y1():
print 'y1 executed'
...
>>> def y2():
print 'y2 executed'
...
>>> for f in [y1,y2]:
name = f.__name__
print name; f()
t=timeit.Timer('%s()' % name, 'from __main__ import %s' % name)
print t.timeit(1)
...
y1
y1 executed
y1 executed
0.00186991691589
y2
y2 executed
y2 executed
0.00309705734253
>>> import sys
>>> sys.version
'2.3 (#1, Sep 13 2003, 00:49:11) \n[GCC 3.3 20030304 (Apple Computer,
Inc. build 1495)]'
>>>
On Apr 19, 2005, at 2:16 AM, Chris Smith wrote:
> I sent the following to the mac-sig without reply (except for an
> autoresponder telling me that a person was out of the office :-)). Is
> there anyone with a mac that could test this code in the IDE to see if
> you have the same problems? (I don't have problems running it through
> the 2.4 version of python in the terminal.)
>
> =====
>
> I was recently trying to use the timeit module and although I was able
> to do so without problem on a Windows machine, I get a "cannot import
> y1" ImportError from the following script.
>
> ###
> import timeit
> def y1():
> print 'y1 executed'
> def y2():
> print 'y2 executed'
> for f in [y1,y2]:
> name = f.__name__
> print name; f()
> t=timeit.Timer('%s()' % name, 'from __main__ import %s' % name)
> print t.timeit(1)
> ###
> --the output--
> y1
> y1 executed
> ** ImportError
>
> I am using the IDE for 2.3.3 under OS X (10.2.8).
>
> I am able to successfully run timeit in other ways, but I like the
> above way to loop through the codes that I want to test.
>
> /c
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list