Skip to content

Instantly share code, notes, and snippets.

Created Mar 17, 2010

What would you like to do?
class Vector:
Demo of a class with multiple signatures for the constructor
def __init__(self, constructor=()):
self.values = list(constructor)
def from_values(cls, *args):
return cls(args)
# There's no real reason to have a separate vector constructor, we could do this:
def __iter__(self):
return iter(self.values)
# otherwise:
def from_vector(cls, vector):
return cls(vector.values)
#------------ end of class definition ---------------------
v = Vector.from_values(1,2,3)
v = Vector([4,5,6])
q = Vector.from_vector(v);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.