pdir 古城微笑少年丶 2024-04-18 22:34 5阅读 0赞 ### pdir ### * 前言 * 安装 * 比较 * * dir * pdir # 前言 # python 内置函数dir, dir() 函数:不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表。如果参数包含方法\_\_dir\_\_(),该方法将被调用。如果参数不包含\_\_dir\_\_(),该方法将最大限度地收集参数信息。 第三方库pdir 以更加友好的方式显示信息 # 安装 # pip install pdir # 比较 # ## dir ## print(dir([])) 输出 ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] ## pdir ## 源代码 import pdir print(pdir([])) 输出 special attribute: __class__, __doc__ abstract class: __subclasshook__ arithmetic: __add__, __iadd__, __imul__, __mul__, __rmul__ object customization: __format__, __hash__, __init__, __new__, __repr__, __sizeof__, __str__ rich comparison: __eq__, __ge__, __gt__, __le__, __lt__, __ne__ attribute access: __delattr__, __dir__, __getattribute__, __setattr__ class customization: __init_subclass__ container: __contains__, __delitem__, __getitem__, __iter__, __len__, __reversed__, __setitem__ pickle: __reduce__, __reduce_ex__ function: append: Append object to the end of the list. clear: Remove all items from list. copy: Return a shallow copy of the list. count: Return number of occurrences of value. extend: Extend list by appending elements from the iterable. index: Return first index of value. insert: Insert object before index. pop: Remove and return item at index (default last). remove: Remove first occurrence of value. reverse: Reverse *IN PLACE*. sort: Stable sort *IN PLACE*. 通过比较可知,pdir 能够更好的显示信息
相关 pdir pdir * 前言 * 安装 * 比较 * * dir * pdir 前言 python 内置函数dir, dir() 函数:... 古城微笑少年丶/ 2024年04月18日 22:34/ 0 赞/ 6 阅读
还没有评论,来说两句吧...