- #1
fog37
- 1,549
- 107
- TL;DR Summary
- better understand the type of output of dir() function
Hello,
Simple clarification about the built-in function dir() if possible: if we don't provide any argument, i.e. we use the function simply as dir(), the function displays the namespace of the function, of the module, etc.
However, if we provide an input, the function dir() displays a list of all the methods and attributes that that particular object has. For example, if we class, Dog(), and then we create an instances, dog1=Dog(), we can type dir(dog1) to see all the attributes and methods associated to the instance dog. Would that be equivalent to the namespace for that specific object?
In general, when talking about namespaces, we refer to local namespaces (for functions; can multiple local namespaces exist at the same time or only one at a time?), global namespaces (which pertain to modules. Can multiple global namespaces exist at once or only one at a time) and built-in namespace (only one built-in namespace exists).
In essence, does dir() show the content of a namespace or the attributes+methods of an object? Or both depending on the input to dir()?
Thanks!
Simple clarification about the built-in function dir() if possible: if we don't provide any argument, i.e. we use the function simply as dir(), the function displays the namespace of the function, of the module, etc.
However, if we provide an input, the function dir() displays a list of all the methods and attributes that that particular object has. For example, if we class, Dog(), and then we create an instances, dog1=Dog(), we can type dir(dog1) to see all the attributes and methods associated to the instance dog. Would that be equivalent to the namespace for that specific object?
In general, when talking about namespaces, we refer to local namespaces (for functions; can multiple local namespaces exist at the same time or only one at a time?), global namespaces (which pertain to modules. Can multiple global namespaces exist at once or only one at a time) and built-in namespace (only one built-in namespace exists).
In essence, does dir() show the content of a namespace or the attributes+methods of an object? Or both depending on the input to dir()?
Thanks!