Skip to content

Instantly share code, notes, and snippets.

@leehosung
Created January 27, 2016 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leehosung/f0429801f937d2ab6196 to your computer and use it in GitHub Desktop.
Save leehosung/f0429801f937d2ab6196 to your computer and use it in GitHub Desktop.
생성자에서 옵션받기
class A(object):
def __new__(cls, version=0):
if version==0:
return super(A, cls).__new__(cls)
elif version==1:
return A1.__new__(A1)
def whoami(self):
print("A")
class A1(A):
def whoami(self):
print("A1")
a = A()
a.whoami()
a1 = A(version=1)
a1.whoami()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment