[Tutor] function won't import from module

Alan G alan.gauld at freenet.co.uk
Tue Aug 9 09:42:51 CEST 2005


I can't see a problem but I notice an inconsistency below:

> #testof_cmpSeq.py
> 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...

> #testof_print_hms
> import mycalc
> seconds = 87658
> mycalc.print_hms(seconds)

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. 

More information about the Tutor mailing list