[Python]How to use magic methods in Python?
程序员文章站
2022-09-10 12:54:21
in this article, i write a simple code example to explore how to use super,new,init and st...
in this article, i write a simple code example to explore how to use super,new,init and str magic method in python.
class mainclass(object): def __new__(cls,*args,**kwargs): print 'this is the new method' return super(mainclass,cls).__new__(cls, *args,**kwargs) #return object.__new__(cls,*args,**kwargs) def __init__(self): print 'this is init method' def __str__(self): return 'test the string method' def main(): #help(object) instance = mainclass() print str(instance) if __name__ == '__main__': main()
推荐阅读
-
Python socket.error: [Errno 98] Address already in use的原因和解决方法
-
python使用magic模块进行文件类型识别方法
-
[Python]How to use magic methods in Python?
-
「Python」Linux环境下启动Flask应用时失败,Error:Address already in use
-
Python Magic—条件语句与循环语句
-
[Python] How to use Pyramid?
-
Day 4--robot api with yaml: Use your python scripts as robot keywords
-
Python魔术方法-Magic Method
-
Python socket.error: [Errno 98] Address already in use的原因和解决方法
-
草根学Python(十)Python 的 Magic Method