[Tutor] import of source code still not working

Adam adam.jtm30 at gmail.com
Mon Feb 20 20:04:48 CET 2006


On 20/02/06, Kermit Rose <kermit at polaris.net> wrote:
>
>
>
>  *From:* Jason Massey <jason.massey at gmail.com>
> *Date:* 02/20/06 12:20:03
> *To:* Kermit Rose <kermit at polaris.net>
> *Cc:* tutor at python.org
> *Subject:* Re: [Tutor] import of source code still not working
>
>
> 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 *
>
> Which will put all of your functions into the global namespace.
>
> Then you can call factor() & factor0()  as you would expect to.
>
>
> *******
>
> Thank you very much
>
> 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'
> >>> v
> [2, 35715, 17859, -318417088, 8932, 17860, 1000009, 5]
>
>
> Listing of transfac function is
>
>
> def transfac(v):
> #  import random
> #   begin level 0
>   a = v[0]
>   b = v[1]
>   c = v[2]
>   d = v[3]
>   m = v[4]
>   n = v[5]
>   z =
> v[6]
> #  line 10
>   k = v[7]
>   k = k + 1
>   a2 = a%2
>   b2 = b%2
>   c2 = c%2
>   d2 = d%2
> #  ma = ((d - n * c)/(a*m + b))/4
> #  ma = random.randint(1,min(abs(ma),abs(m))+1)
> #  na = ((d - m * b)/(a * n +c) )/4
> #  na = random.randint(1,min(abs(na),abs(n))+1)
> # line 20
> #  if v[3]<0:
> #      na=-na
> #      ma=-ma
> #  ma = ma * random.randint(0,1)
> #  if ma=0:
> #      pass
> #  else
> #      na = na * random.randint(0,1)
>   j = 8 * a2 + 4 * b2 + 2 * c2 + d2
>   if j == 0:  a,b,c,d,m,n =
> a/2,b/2,c/2,d/2,m,n                                    #     line 30
>   if j == 1:  a,b,c,d,m,n = -1,-1,-1,-1,-1,-1
>   if j == 2:  a,b,c,d,m,n = a,b/2,c,d/2,m,2*n
>   if j == 3:  a,b,c,d,m,n = a,(a+b)/2,c,(d-c)/2,2*n+1
>   if j == 4:  a,b,c,d,m,n = a,b,c/2,d/2,2*m,n
>   if j == 5:  a,b,c,d,m,n = a,b,(a+c)/2,(d-b)/2,2*m+1,n
>   if j == 6:
>       #  begin if level 1
>       if b>c:
>           # begin if level 2
>
> t=(d-b*m)/(a+c*m)
> # line 40
>
> t=t/4
>           print t
>           if t==0: t=1
>           print a,b,c,d,m,n
>           a,b,c,d,m,n = a,b.c+a*t,d-b*t,m+t,n
>           # end if level
> 2
> #  line 46
>       else:
>           # begin if level 2
>           t=(d-c*n)/(b+a*m)
>
> t=t/4
> #     line 50
>           if t==0:  t=1
>           a,b,c,d,m,n = a,b+a*t,c,d-c*t,m,n+t
>           #   end if level 2
>        # end if level 1
> #      a,b,c,d,m,n = a,a*na+b,a*ma+c,d-a*ma*na - b*ma - c * na,m+ma,n+na
>   if j == 7:
>       # begin if level 1
>       if b>c:
>       # begin if level 2
>           t=(d - b * m)/(c + a*m)
>           t=t/4
>           if t == 0:  t=1
>           a,b,c,d,m,n = a,b,c+a*t,d-b*t,m+t,n
>       else:
>       #  continue if level 2
>           t=(d - c * n)/(b+a*n)
>           t=t/4
>           if t == 0:    t=1
>           a,b,c,d,m,n = a,b+a*t,c,d-c*t,m,n+t
>           # end if level 2
>     # end if level 1
>   if j == 8:  a,b,c,d,m,n = -1,-1,-1,-1,-1,-1
>   if j == 9:  a,b,c,d,m,n = 2*a,a+b,a+c,(d-a-b-c)/2,2*m+1,2*n+1
>   if j == 10:
>       # begin if level 1
>       if b>c:
>           # begin if level 2
>           t=(d - b * m)/(c + a * m)
>           t=t/4
>           if t==0:  t=1
>           a,b,c,d,m,n = a,b,c+a*t,d-b*t,m+t,n
>           # end if level 2
>       else:
>       # continue if level 1
>           t=(d - c * n)/(c + a * n)
>           t=t/4
>           if t==0:  t=1
>           a,b,c,d,m,n = a,b+a*t,c,d-c*t,m,n+t
>           #  end if level 2
>   # end if level 1
>   if j == 11: a,b,c,d,m,n = 2*a,a+b,c,(d-c)/2
>   if j == 12:
>       # begin if level 1
>       if b>c:
>           # begin if level 2
>           t=(d - b * m)/(c + a * m)
>           t=t/4
>           if t==0:  t=1
>           a,b,c,d,m,n = a,b,c+a*t,d-b*t,m+t,n
>       else:
>           # continue if level 2
>           t=(d - c * n)/(b + a * n)
>           t=t/4
>           if t==0: t=1
>           a,b,c,d,m,n = a,b+a*t,c,d-c*t,m,n+t
>         # end if level 2
>       # end if level 1
>   if j == 13: a,b,c,d,m,n = 2*a,b,a+c,(d-b)/2,m,2*n+1
>   if j == 14: a,b,c,d,m,n = 2*a,b,c,d/2,2 *m,2*n
>   if j == 15:
>       # begin if level 1
>       if b>c:
>           # begin if level 2
>           t=(d - b * m)/(c + a * m)
>           t=t/4
>           if t==0: t=1
>           a,b,c,d,m,n = a,b,c+a*t,d-b*t,m+t,n
>       else:
>           # continue if level 2
>           t=(d - c * n)/(b + a * n)
>           t=t/4
>           if t==0: t=1
>           a,b,c,d,m,n = a,b+a*t,c,d-c*t,m,n+t
>           #  end if level 2
>     # end if level 1
>   z = a * d + b * c
>   v = [a,b,c,d,m,n,z,k]
>   return  v
> #  end routine level
>

Kermit have you actually bothered going through any tutorials? You just seem
to be asking every time you get an error, I know the list is here for people
to ask questions but you really should try and work some things out for
yourself.

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'

Your problem here is that you have b.c instead of what I presume should be a
comma. b.c means that it's trying to find the method c of the integer b
which doesn't exist.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060220/25e0c1f7/attachment.html 


More information about the Tutor mailing list