[Tutor] import of source code still not working

Alan Gauld alan.gauld at freenet.co.uk
Mon Feb 20 21:53:43 CET 2006


>>If you don't want to have to put the factor30 in front of all your 
>>function
>> names you can do this:
>>
>> from factor30 import *

But this is generally considered bad practice since the same function
name can appear in many modules so the last module imported will
hide all the others. The small increase in typing is a small price to pay
for much more reliable code.

You can control visibility by doing

from factor30 import factor, someOtherFunc, andAnother

ie list the names you need to use explicitly. That way you
can see potential name clashes more easily.

> Next dilemma is:
>>> v = [2, 35715, 17859, -318417088, 8932, 17860, 1000009, 5]
>>> v = transfac(v)
-1
2 35715 17859 -318417088 8932 17860

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in -toplevel-
    v = transfac(v)
  File "c:\math\factoring\factor30.py", line 46, in transfac
    a,b,c,d,m,n = a,b.c+a*t,d-b*t,m+t,n
AttributeError: 'int' object has no attribute 'c'

#############

Read the error message carefully then look at the code.
int object with nom attribute c.
where does c appear? You have a dot between b and c
which I assume should be a comma. Dot notation is how
you access attributes of an object - like the functions in
a module for example. Sop Python is looki8ng for the
c attribute of b but b is a number...

HTH,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list