[Tutor] AttributeError: Vector instance has no attribute 'Normalize'

spir denis.spir at free.fr
Fri Nov 27 21:59:24 CET 2009


Garrett Hartshaw <ghartshaw at gmail.com> wrote:

> The program I am writing gives the following error message when run.
> 
> Traceback (most recent call last):
>   File "./space.py", line 177, in <module>
>     main()
>   File "./space.py", line 173, in main
>     player = Ship("space/models/fighter.3ds",
> "space/models/realistic.bmp", Quaternion(), Vector(0, 0, -30), 1, 0.1)
>   File "./space.py", line 131, in __init__
>     Object.__init__(self, obj, tex, rot, pos)
>   File "./space.py", line 124, in __init__
>     self.model = Model(obj)
>   File "./space.py", line 80, in __init__
>     self.CalcNormals()
>   File "./space.py", line 90, in CalcNormals
>     vectB = (vectA - vectB).Normalize()
> AttributeError: Vector instance has no attribute 'Normalize'
> 
> The definition for Vector is:
> 
> class Vector:
>     def __init__(self, x=0, y=0, z=0):
>         self.x = x
>         self.y = y
>         self.z = z
> 
>     def Normalize(self):
>         return self / self.Length()
> 
>     def __sub__(self, right):
>         return Vector(self.x - right.x, self.y - right.y, self.z - right.z)
> 
> so I cannot figure out what the error is.

You may print out the given vector's attr list using dir to check, or just check it actually holds a Normalise method, exactly at the point you want its norm. Something like:
    v = (vectA - vectB)
    print (hasattr(v, "Normalise")); print (v.__class__)
    vectB = v.Normalise()

The second print() is for this reason: I bet you have several instances (;-) of the Vector class on your system, and the one actually used is not the one you guess...

> (o_
> //\
> V_/_
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor




________________________________

la vita e estrany

http://spir.wikidot.com/



More information about the Tutor mailing list