python – 什么是func_dict?

python – 什么是func_dict?,第1张

概述如果我在 python中创建一个简单的函数,它同时具有__dict__和func_dict作为属性,两者都以空字典开头: >>> def foo():... return 42... >>> foo.__dict__{}>>> foo.func_dict{} 如果我向foo添加一个属性,它会显示在两者中: >>> foo.x = 7>>> foo.__dict__{'x': 如果我在 python中创建一个简单的函数,它同时具有__dict__和func_dict作为属性,两者都以空字典开头:
>>> def foo():...     return 42... >>> foo.__dict__{}>>> foo.func_dict{}

如果我向foo添加一个属性,它会显示在两者中:

>>> foo.x = 7>>> foo.__dict__{'x': 7}>>> foo.func_dict{'x': 7}

这些属性有什么区别?是否存在一个特定用例?

解决方法 它们是同一个潜在词典的别名.你应该使用__dict__,因为func_dict已经在Python 3中消失了. 总结

以上是内存溢出为你收集整理的python – 什么是func_dict?全部内容,希望文章能够帮你解决python – 什么是func_dict?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1207054.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-04
下一篇2022-06-04

发表评论

登录后才能评论

评论列表(0条)

    保存