Created
January 27, 2016 02:50
-
-
Save leehosung/f0429801f937d2ab6196 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 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