简体   繁体   English

在Python中,method_descriptor是什么?

[英]In Python, what is a method_descriptor?

In Python, what is a method_descriptor (in plain English)? 在Python中,method_descriptor(用简单的英语)是什么?

I had this error, and I can't really find any information on it: 我遇到了这个错误,但实际上找不到任何信息:

*** TypeError: can't pickle method_descriptor objects

Switch to dill . 切换到dill

I am not interested in debugging this error... 我对调试此错误不感兴趣...

You should be. 你应该。 If you're uninterested in debugging errors, you're in the wrong field. 如果您对调试错误不感兴趣,那么您将选择错误的字段。 For the sake of polite argumentation, let's charitably assume you authored that comment under the duress of an unreasonable deadline. 为了有礼貌地论证,让我们慈善地假设您在不合理的截止日期的胁迫下撰写了该评论 ( It happens. ) 发生

The standard pickle module is incapable of serializing so-called "exotic types," including but presumably not limited to: functions with yields , nested functions, lambdas, cells, methods, unbound methods, modules, ranges, slices, code objects, methodwrapper objects, dictproxy objects, getsetdescriptor objects, memberdescriptor objects, wrapperdescriptor objects, notimplemented objects, ellipsis objects, quit objects, and ( ...wait for it! ) method_descriptor objects. 标准pickle模块是不能序列化所谓的“外部类型,”包括但据推测不限于:与功能yields ,嵌套函数,lambda表达式,细胞,方法,未结合的方法,模块,范围,切片, code对象, methodwrapper对象, dictproxy对象, getsetdescriptor对象, memberdescriptor对象, wrapperdescriptor对象, notimplemented对象, ellipsis对象, quit对象,以及( ... waiting it!method_descriptor对象。

All is not lost, however. 但是,一切并没有丢失。 The third-party dill package is capable of serializing all of these types and substantially more. 第三方dill 能够序列化所有这些类型的并且基本上更多的。 Since dill is a drop-in replacement for pickle , globally replacing all calls across your codebase to the pickle.dump() function with the equivalent dill.dump() function should suffice to pickle the problematic method descriptors in question. 由于dill是一个简易替代pickle ,全球替换所有来电在您的代码库的pickle.dump()具有同等功能dill.dump()函数应该足以酸洗问题的方法描述符的问题。

I just want to know what a method_descriptor is, in plain English. 我只想用简单的英语知道method_descriptor是什么。

No, you don't. 不,你没有。 There is no plain-English explanation of method descriptors, because the descriptor protocol underlying method descriptors is deliciously dark voodoo. 方法的描述没有纯英文的解释,这是因为描述协议基本方法的描述是美味的黑巫术。

It's voodoo, because it has to be; 这是伏都教,因为它必须是伏都教。 it's the fundamental basis for Python's core implementation of functions, properties, static methods, and class methods. 它是Python的函数,属性,静态方法和类方法的核心实现的基础。 It's dark, because only a dwindling cabal of secretive Pythonistas are actually capable of correctly implementing a descriptor in the wild. 这是黑暗的,因为只有越来越少的秘密Pythonista才真正能够在野外正确实现描述符。 It's delicious, because the power that data descriptors in particular provide is nonpareil in the Python ecosystem. 这很美味,因为数据描述符特别提供的功能在Python生态系统中无与伦比。

Fortunately, you don't need to know what method descriptors are to pickle them. 幸运的是,您不需要知道要腌制它们的方法描述符。 You only need to switch to dill . 您只需要切换到dill

method_descriptor is a normal class with __get__ , __set__ and __del__ methods. method_descriptor是与正常的类__get____set____del__方法。 You can check the link for more info at Static vs instance methods of str in Python 您可以在Python的str的静态与实例方法中查看更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python内省:获取method_descriptor的参数列表? - Python introspection: get the argument list of a method_descriptor? Spark无法pickle method_descriptor - Spark can't pickle method_descriptor python - django:为什么我收到此错误:AttributeError:'method_descriptor'对象没有属性'今天'? - python - django: why am I getting this error: AttributeError: 'method_descriptor' object has no attribute 'today'? AttributeError: 'method_descriptor' object 在替换字符串时在 python 中没有属性 'df_new' - AttributeError: 'method_descriptor' object has no attribute 'df_new' in python when replacing string method_descriptor object 没有属性“现在” - 在 function 返回时 - method_descriptor object has no attribute 'now' - while returning in function kivy-TypeError:描述符“属性”需要一个“ kivy._event.EventDispatcher”对象,但收到一个“ method_descriptor” - kivy - TypeError: descriptor 'property' requires a 'kivy._event.EventDispatcher' object but received a 'method_descriptor' 类级别的 classmethod() 只能在 method_descriptor 或实例方法上调用 - Class-level classmethod() can only be called on a method_descriptor or instance method python中的pickling方法描述符对象 - Pickling method descriptor objects in python 我可以在python 3中为描述符定义add方法吗? - Can I define an add method for a descriptor in python 3? 什么时候调用python描述符方法? - When python descriptor method would be called?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM