Created
March 17, 2010 23:22
-
-
Save anonymous/335850 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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