Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mirekfranc/2c3f269b88b970932042 to your computer and use it in GitHub Desktop.
Save mirekfranc/2c3f269b88b970932042 to your computer and use it in GitHub Desktop.
Alternative constructors and static methods in python...
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