Python dir FunctionLast modified April 11, 2025 This comprehensive guide explores Python's dir function, which returns a list of valid attributes for an object. We'll cover basic usage, custom objects, and practical examples of object introspection. ...
除此之外,help()还可以做很多事,例如查看模块的帮助信息,以及Python关键字和运算符的信息。 >>> help(sum) #查看内置函数的帮助文档 Help on built-in function sum in module builtins: sum(iterable, start=0, /) Return the sum of a 'start' value (default: 0) plus an iterable of numbers When ...
If the object has a method named __dir__(), this method will be called and must return the list of attributes. This allows objects that implement a custom __getattr__() or __getattribute__() function to customize the way dir() reports their attributes. ...
If the object does not provide __dir__(), the function tries its best to gather information from the object’s __dict__ attribute, if defined, and from its type object. The resulting list is not necessarily complete, and may be inaccurate when the object has a custom __getattr__()....
【Python】Python内置函数dir详解 1.命令介绍 最近学习并使用了一个python的内置函数dir,首先help一下: 复制代码代码如下: >>> help(dir) Help on built-in function dir in module __builtin__: dir() dir([object]) -> list of strings Return an alphabetized list of names comprising (some of) the...
If the object does not provide__dir__(), the function tries its best to gather information from the object’s__dict__attribute, if defined, and from its type object. The resulting list is not necessarily complete, and may be inaccurate when the object has a custom__getattr__(). ...
ExampleGet your own Python ServerDisplay the content of an object:class Person: name = "John" age = 36 country = "Norway" print(dir(Person))Try it Yourself » Definition and UsageThe dir() function returns all properties and methods of the specified object, without the values....
(2)内置函数help()用来返回对象的帮助信息,尤其常用来查看函数或对象方法的帮助信息。除此之外,help()还可以做很多事,例如查看模块的帮助信息,以及Python关键字和运算符的信息。 >>> help(sum) #查看内置函数的帮助文档 Help on built-in function sum in module builtins:sum(iterable, start=0, /) ...
Python: dir() function Last update on August 19 2022 21:51:34 (UTC/GMT +8 hours) dir() function The dir() function returns all properties and methods of the specified object, without the values. The function will return all the properties and methods, even built-in properties which are...
各版本中都支持该函数,python3中仍可用。 代码示例: >>> import struct >>> dir() # show the names in the module namespace ["__builtins__", "__doc__", "__name__", "struct"] >>> dir(struct) # show the names in the struct module ...