不受约束的方法?那是什么? [英] Unbound method? What's that?

查看:68
本文介绍了不受约束的方法?那是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以快速了解绑定和未绑定方法之间的区别吗?我遇到了关于未绑定方法的错误,并发现了很多关于改变Python行为的讨论,但到目前为止我的任何阅读材料都没有遇到过这些描述。


谢谢!

Can someone give me a quick rundown on the difference between bound and unbound methods? I ran into an error regarding an unbound method, and found lots of discussions about changing Python behavior regarding them, but haven''t come across these descriptions in any of my reading material so far.

Thanks!

推荐答案

好的,我在这里缺少一些非常基本的东西。


这是什么我正在玩:


OK, I''m missing something really basic here.

Here''s what I''m playing with:


展开 | 选择 | Wrap | 行号



有人能给我一个简短的概述o n绑定和非绑定方法之间的区别?我遇到了关于未绑定方法的错误,并发现了很多关于改变Python行为的讨论,但到目前为止我的任何阅读材料都没有遇到过这些描述。


谢谢!
Can someone give me a quick rundown on the difference between bound and unbound methods? I ran into an error regarding an unbound method, and found lots of discussions about changing Python behavior regarding them, but haven''t come across these descriptions in any of my reading material so far.

Thanks!



我唯一需要记住的是我需要处理实例。例如:



>>> aClass类:

... def aClassFuntion(个体经营):

...传递

...

>>> aClass.aClassFuntion()

文件"< console>",第1行,在?

''''''exceptions.TypeError:未绑定方法aClassFuntion( )必须使用aClass实例作为第一个参数调用(没有任何代替)'''''

>>> instance = aClass()

>>> instance.aClassFuntion()

>>>

The only thing that I''ve ever needed to remember is that I need to work with instances. For example:


>>> class aClass:
... def aClassFuntion(self):
... pass
...
>>> aClass.aClassFuntion()
File "<console>", line 1, in ?
'''''' exceptions.TypeError : unbound method aClassFuntion() must be called with aClass instance as first argument (got nothing instead) ''''''
>>> instance = aClass()
>>> instance.aClassFuntion()
>>>


展开 | < span class =codeLinkonclick =selectAll(this);>选择 | Wrap | 行号


这篇关于不受约束的方法?那是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆