Skip to content

Instantly share code, notes, and snippets.

Created March 17, 2010 23:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/335850 to your computer and use it in GitHub Desktop.
Save anonymous/335850 to your computer and use it in GitHub Desktop.
class Vector:
"""
Demo of a class with multiple signatures for the constructor
"""
def __init__(self, constructor=()):
self.values = list(constructor)
@classmethod
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:
@classmethod
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