티스토리 뷰

공부

[Python] __new__ return constructor

승가비 2022. 5. 7. 19:03
728x90
class MyClass(object):
    def __init__(self):
        print "never called in this case"
    def __new__(cls):
        return 42

obj = MyClass()
print obj

https://stackoverflow.com/questions/2491819/how-to-return-a-value-from-init-in-python

 

How to return a value from __init__ in Python?

I have a class with an __init__ function. How can I return an integer value from this function when an object is created? I wrote a program, where __init__ does command line parsing and I need t...

stackoverflow.com

 

728x90
댓글