如何获取所有特殊方法的列表? [英] How can i get a list of all special methods available?

查看:136
本文介绍了如何获取所有特殊方法的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

特殊方法是(在Django中):

Special methods are for example (in Django):

def __wrapper__
def __deepcopy__
def __mod__
def __cmp__


推荐答案

方法名称是这里,但它并不是详尽的魔术名字 - 例如, __ copy __ 和 __ deepcopy __ org / library / copy.html?highlight = __ copy__rel =noreferrer>这里,而 __ all __ 变量是 here ,类属性如 __ name __ __ bases __ 等等都是 here ,等等。我不知道在任何给定版本的语言中定义的所有这样的名称的任何一个权威性列表。

A list of special method names is here, but it's not an exhaustive of magic names -- for example, methods __copy__ and __deepcopy__ are mentioned here instead, the __all__ variable is here, class attributes such as __name__, __bases__, etc are here, and so on. I don't know of any single authoritative list of all such names defined in any given release of the language.

但是,如果你想检查任何一个给定的特殊名称,说 __ foo __ ,只需在Python文档的快速搜索框中搜索(任何上述URL都可以!) - 这样你会发现如果它正式是语言的一部分,如果你找到它,你会知道这是一个错误的使用,一些包或框架的一部分违反了语言的惯例。

However, if you want to check on any single given special name, say __foo__, just search for it in the "Quick search" box of the Python docs (any of the above URLs will do!) -- this way you will find it if it's officially part of the language, and if you don't find it you'll know it is a mistaken usage on the part of some package or framework that's violating the language's conventions.

这篇关于如何获取所有特殊方法的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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