Skip to content

Instantly share code, notes, and snippets.

Created July 23, 2014 06:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fsword/0f9305ac87466142bbbc to your computer and use it in GitHub Desktop.
sample code to explain the fail design of default argument support in python
class Member:
def __init__(self,name='',group=''): = name = group
class Team:
def __init__(self, names):
self.members = [Member(n,str(hash(self))) for n in names]
def join_us(self,member=Member()):
self.members.append(member) = str(hash(self))
return member
def print_members(self):
for n in self.members:
dev_team = Team(['john'])
test_team = Team(['smith','tom'])
tom = test_team.members[1]
new_guy = dev_team.join_us() = 'xman'
another_new_guy = dev_team.join_us() = 'jim'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment