概述
class TestClass(object): def __init__(self): self.arg = "arg" def test(): print("Hey test")
并使用:
>>> TestClass.test() "Hey test"
我知道在Python中有标准方法,其中self作为参数(不知道如何正确调用它们),静态方法,类方法,抽象方法.
编辑:
Note that the transformation from function object to instance method
object happens each time the attribute is retrieved from the instance.
[强调我的]
您恰好使用正确的参数集调用函数,尽管通过类对象访问.与通过实例调用方法的基础函数对象相同:
TestClass().test.__func__() # "Hey test"
快速测试进一步解释:
print(TestClass().test is TestClass.test) # False print(TestClass().test.__func__ is TestClass.test) # True
但是,在Python 2中,行为是不同的,因为当通过类或实例访问属性时,会发生从函数对象到方法对象的转换:
Note that the transformation from function object to (unbound or
bound) method object happens each time the attribute is retrieved from
the class or instance.
[强调我的]
总结
以上是编程之家为你收集整理的python – 没有自我的内部类函数全部内容,希望文章能够帮你解决python – 没有自我的内部类函数所遇到的程序开发问题。
如果您也喜欢它,动动您的小指点个赞吧