首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python self使用args,self(args)

Python self使用args,self(args)
EN

Stack Overflow用户
提问于 2016-06-03 00:24:41
回答 1查看 874关注 0票数 1

我不太明白这个代码是什么意思:

代码语言:javascript
复制
# instantiate the input layer
x = Input(batch_shape=batch_input_shape,
          dtype=input_dtype, name=name)
# this will build the current layer
# and create the node connecting the current layer
# to the input layer we just created.
self(x)

此代码位于一个类的成员函数中,请参考https://github.com/fchollet/keras/blob/master/keras/engine/topology.py第341行。当我步入self(x)时,它跳转到这个类的另一个成员函数__call__。这一切为什么要发生?谢谢。

EN

回答 1

Stack Overflow用户

发布于 2016-06-03 00:30:17

__call__()是Python语言中的一种特殊方法。它允许类模拟函数类型。

按照惯例,self可能是成员函数的第一个参数,即方法被调用的对象的实例。

因此,self()使用当前实例对象作为函数。根据定义,这意味着对象上的__call__()方法将被调用,这正是发生的事情。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37597268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档