I'm trying to make a class with a variable parameter list, the code:
Vector.py class code:
class Vector(tuple):
def __new__(cls, *V):
return tuple.__new__(cls, V)
def __init__(self, *V):
self.V = V
def __repr__(self):
"""An overloaded method that it writes a vector in a terminal."""
return('({})'.format(self))
TestVector.py code:
from Vector import Vector
def main():
'We create 2 Vectors'
V1 = Vector((3, 2))
V2 = Vector((4, 5))
print(V1)
print(V2)
When I execute the code I obtain none error message, only a white line.
Thanks
__new__if you want to assign to a tuple like this.__repr__is called when you try to turn theVectorobject into a string.