python - Modify input arguments of inherited class before initializing parent class -


I am creating a geometry module I have defined GeoTuple, Vector (GeoTuple), Normal (Vector). Because in general there should be a magnitude of 1, I need to modify the input arguments and modify them before starting the vector, see the code below:

  Category GeoTuple (Tupal, Object): Def __init __ (self, data): try: if lane (data)! = 3: Increase ValueError ("vector should have only 3 members") _floats = tuple (float (item) for item in data) Super (GeoTuple, self) .__ init __ (_ Floats)) Finally: Close def __ ADD __ (Self, B): Increase the NERR ("The integration for geotuple has been disabled") DEF __ool __ (self, b): Name Enter (JLOW copies have been disabled for geographical) square vector (Geoteplay, object): def __init __ (self, point): super (vector, self) .__ init __ ( @) Property def (Self): Return self [0] @ Property Def Y (Self): Return Self [1] @ Property Def Z: (Self) Returns [2] @ Property Deficit (self): _x , _y, _z = self return sqrt (_x ** 2+ _y ** 2 + _z ** 2) def __add __ (self, b): _p = (self. X + bx, self. E +, self. + Bez) Return Vector (_p) def __sub __ (self, b): _p = (auto.x - bx, by itself, by itself .z - bz) return vector (_p) def __mul __ (self, b ): If Eastense B, self .__ class__): _s = self.x * bx + s Elf.y * by + self.z * bz result = _s else: _s = float (b) _p = (self.x * _s, self.y * _s, self.z * _s) result = vector (_p) return The result DEF __B __ (self): return vector ((abdomen (self (xx), abs (self), abs (self. J.))) DEF __neg__ (self): return vector ((self.x, -self.y, -self.z)) DRF cross (self, b): _p = [self.a * bees - self. Z * S, Self. * Bx - self.x * bz, self.x * By - Self. Y * bx] return vector (_p) def __xor __ (self, b): returns self.cross (b) square normal (vector, object): DEF __int_ (self, data): _x, _y, _z = data _mag = Sqrt (_x ** 2+ _y ** 2 + _z ** 2) _p = [_x / _mag, _y/ _mag, _z/ _mag] super (vector, self) .__ init __ (_p) problem  > 

This return:

  (1,3,8)  

not

   

Edit 1

I have changed the parameter name to the data from the normal point (it's just a copy Paste error was) it is necessary that G EoTuple remains unchanging, so it seems that new will be the way to implement it? Can you provide a concrete example?

Tuples are irreversible and therefore it is __init__ a child is late or You can overwrite it on __ new __ or change your base class to a list which is unstable.

This works:

  class GeoTuple (list, object): #list not tuple .... class Normal (vector, object): def __init __ ( Self, point): _x, _y, _z = dot #same name param _mag = (_x ** 2 + _y ** 2 + _z ** 2) ** .5 _p = [_x / _mag, _y / _mag, _z / _mag] Super (normal, self) .__ init __ (_p) #right class name n1 = normal ([1,3,8]) print n1  

and output is :

  [0.11624763874381928, 0.34874291623145787, 0.9299811099505543]  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -