[Tutor] function won't import from module

Dick Moores rdm at rcblue.com
Tue Aug 9 11:35:04 CEST 2005

Alan G wrote at 00:42 8/9/2005:
>I can't see a problem but I notice an inconsistency below:
>>import mycalc
>>which produces:
>>Traceback (most recent call last):
>>   File "C:\Python24\MyScripts\testof_cmpSeq.py", line 1, in -toplevel-
>>     from mycalc import cmpSeq
>>ImportError: cannot import name cmpSeq
>In the code snippet you claim to use import mycalc but the error
>suggests you used 'from mycalc import cmpSeq'.
>I don't know which is correct and they should both work, but it might
>be worth checking if it makes a difference.
>Also was it a freshj interpreter session or was your interactive
>version of cmpSeq sttill around? Again it shouldn't have been a
>problem but...
>>import mycalc
>>seconds = 87658
>Whereas here you are definitely using import mycalc.
>Did you do this after adding cmpSeq? If so it would appear that
>Python is happy with the function definition. Did you try calling
>mycalc.cmpSeq in this same session?
>Clutching at straws...
>Alan G.

Yes, I now see the inconsistencies in my post. But they don't accurately 
reflect what I actually did. Sorry. I went back and checked and still got 

I tried deleting a mycalc.pyc that had been created and the problem 
cleared up! If I remember correctly, for a while I had moved mycalc.py to 
another folder in PYTHONPATH (I had recently learned how to modify 
PYTHONPATH in Win XP), and the .pyc was in this folder. Sorry I don't 
remember clearly. But what is clear is the problem cleared up immediately 
after deleting the .pyc. Does this make sense?

Showing mycalc is OK now:

IDLE 1.1
 >>> from mycalc import cmpSeq
 >>> a = range(1,1000)
 >>> b = range(1,1000)
 >>> cmpSeq(a,b)
Sequences are identical, and of length 999

 >>> b[500] = 13
 >>> cmpSeq(a,b)
sequences first differ at index 500
seq1[500] = 501
seq2[500] = 13
len(seq1) = 999
len(seq2) = 999

Now I'll begin to ponder the suggestions made by Javier Ruere.


More information about the Tutor mailing list