python 获取类方法
As a newbie to the excellent world of Python development, I'm not always familiar with the methods provided by imported classes. Oftentimes these classes are well-documented but in the case that methods aren't documented, I found the dir
function useful for getting a list of methods:
作为Python开发卓越世界的新手,我并不总是熟悉导入类提供的方法。 通常,这些类的文档有据可查,但是在没有文档记录方法的情况下,我发现dir
函数对于获取方法列表很有用:
# dir({object})dir(difflib)"""Returns:['Differ', 'HtmlDiff', 'IS_CHARACTER_JUNK', 'IS_LINE_JUNK', 'Match', 'SequenceMatcher', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_calculate_ratio', '_count_leading', '_file_template', '_legend', '_mdiff', '_namedtuple', '_styles', '_table_template', '_test', 'context_diff', 'get_close_matches', 'heapq', 'ndiff', 'reduce', 'restore', 'unified_diff']"""
The snippet above does exactly what you would expect -- provides a list of method names for the viewing!
上面的代码片段完全符合您的期望-提供用于查看的方法名称列表!
翻译自:
python 获取类方法