python __init__ __call__
__call__ 和 __init__半毛钱的关系都没有。
后者是构造类的实例时会调用的方法,并不是构造方法。
前者是在实例上可以呼叫的方法。代码示例如下:
>>> class foo:
def __init__(self):
print "init"
def __call__(self):
print "call"
>>> foo()
init
<__main__.foo instance at 0x0000000002C6EC88>
>>> foo()()
init
call
python __init__ __call__的更多相关文章
- python __init__.py用途
转自http://www.cnpythoner.com/post/2.html Python中的Module是比较重要的概念.常见的情况是,事先写好一个.py文 件,在另一个文件中需要import时, ...
- python __init__.py
python中的Module是比较重要的概念.常见的情况是,事先写好一个.py文 件,在另一个文件中需要import时,将事先写好的.py文件拷贝 到当前目录,或者是在sys.path中增加事先写好的 ...
- 高产的母猪之 python __init__全解
python __init__.py python 识别是不是一个模块的标准是目录下有无 __init__.py 模糊导入 模糊导入中的*中的模块是由__all__来定义的,__init__.py的 ...
- python的__call__、__str__、__repr__、__init__、__class__、__name___、__all__、__doc__、__del__等魔术方法的作用
python中,一切都是对象 在Python中,所有以“__”双下划线包起来的方法,都统称为“Magic Method”--魔术方法 1.__call__:作用是把类实例变成一个可调用对象 在Pyth ...
- python 创建类先执行metaclass父类__new__ > __init__>__call__ 然后再执行自己的__new__>__init__
class MyType(type): def __init__(self,*args,**kwargs): print("Mytype __init__",*args,**kwa ...
- python魔术方法(__init__,__call__,被双下划线包围的方法)
转载link:http://pycoders-weekly-chinese.readthedocs.io/en/latest/issue6/a-guide-to-pythons-magic-metho ...
- python特殊函数 __call__()
__call__ 在Python中,函数其实是一个对象: >>> f = abs >>> f.__name__ 'abs' >>> f(-123) ...
- 通过 python的 __call__ 函数与元类 实现单例模式
简单一句话,当一个类实现__call__方法时,这个类的实例就会变成可调用对象. 直接上测试代码 class ClassA: def __call__(self, *args, **kwargs): ...
- 类和对象的创建过程(元类,__new__,__init__,__call__)
一. type() 1.创建类的两种方式 方式一 class MyClass(object): def func(self,name): print(name) myc = MyClass() pri ...
随机推荐
- 国内公共DNS
DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP数串.通过主机名,最终 ...
- 英语etc怎么发音、单词来历
etc是等等的意思,与and so on 相同 音标/et'set(a)ra/ 源于法语et cetera,也是等等的意思 在计算机操作系统目录(linux和windows)有一个叫etc的目录 里面 ...
- 软工实践练习——使用Git进行代码管理
GITHUB上的预备活动: 注册 创建小组Organization,邀请组员进来 将代码库fork到小组Organization底下 下载并使用GIT: Git的安装 使用Git进行代码管理 1.从百 ...
- ThreadLocal类的实现用法
ThreadLocal是什么呢?其实ThreadLocal并非是一个线程的本地实现版本,它并不是一个Thread,而是threadlocalvariable(线程局部变量).也许把它命名为Thread ...
- linux更改文件所有者命令chown命令的使用困惑
[berry@berry:practice] ls -lrt total -rwxrwxrwx berry berry Dec : f1.txt -rwxrwxrwx berry berry Dec ...
- 【UVALive 3905】BUPT 2015 newbie practice #2 div2-D-3905 - Meteor
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/D The famous Korean internet co ...
- codeforces 86D : Powerful array
Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary su ...
- [IOS UIalert模版]
1.alertview创建 UIAlertView *alert; alert = [[UIAlertView alloc] initWithTitle:@"提示" message ...
- Codeforces 295A Greg and Array
传送门 A. Greg and Array time limit per test 1.5 seconds memory limit per test 256 megabytes input stan ...
- POJ1088滑雪(dp+记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 86411 Accepted: 32318 Description ...