[Tutor] Weird import problem with PythonIDE on Mac (was 'import
problem')
Chris Smith
smichr at bigfoot.com
Thu Apr 21 06:15:35 CEST 2005
On Tuesday, Apr 19, 2005, Lee Cullens wrote:
> 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
>
>> 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)
I wrote this yesterday....
------------------
Well, how bizarre! Now I run the code again (after having restarted the
PythonIDE) and now I can't get it to NOT work. And it previously had
not run for many tries.
I don't suppose this is some sort of quantum effect ;-)
Oh well, I'll keep my eyes open to see if this happens again.
------------------
And now today, the problem is back again :-( What's going on? Here is
a smaller code:
###
def y1():
print 'y1 executed'
for f in [y1]:
name = f.__name__
f()
s1 = '%s()' % name
s2 = 'from __main__ import %s' % name
t=timeit.Timer(s1, s2)
print t.timeit(1)
###
Here is the full report from the traceback window {it's great to be
able to cut and paste from that window, thanks Just}
'''
ImportError: cannot import name y1
Traceback (innermost last)
File "<Untitled Script 1>", line 10, in ?
File "timeit.py", line 158, in timeit
return self.inner(it, self.timer)
File "<timeit-src>", line 3, in inner
'''
** If I click on the edit button it says that <timeit-src> cannot be
found. Is this an error to pay attention to or is that an unrelated
problem of trying to browse a (perhaps compiled) source file?
Here is what I've tried to reproduce the problem:
1) I have restarted the system (10.2.8) and run nothing but this script
and still get the error.
2) removed my PythonStartup and sitecustomize.py codes after quitting;
problem still persists
3) re-installed MacPython 2.3.3 after moving the old version's
macPython 2.3.3 folder to the desktop
4) I have tried running the script in the add with and without the "run
as __main__" option.
I DO NOT have the error show up when I run the script through the
Terminal (i.e. %python timeitproblem.py).
I also DO NOT have the problem if I run the script with PyOXIDE.
As noted yesterday, there are some unknown steps that make the problem
go away, though I do not know what these are yet.
Does anyone else have any insights?
/c
More information about the Tutor
mailing list