Created
May 8, 2015 22:17
-
-
Save mirekfranc/2c3f269b88b970932042 to your computer and use it in GitHub Desktop.
Alternative constructors and static methods in python...
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 MyList(list): | |
# alternative constructor | |
@classmethod | |
def multiple_of(cls, n, c): | |
return cls(c * n) | |
# some random method bundled in the class | |
@staticmethod | |
def print_with_numbers(a): | |
for n, e in enumerate(a): | |
print n, e | |
l = MyList.multiple_of(4, 'x') | |
MyList.print_with_numbers(l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment