Search notes:
Python: dir
dir()
, without an argument, lists the names in the current local scope.
After starting a python shell, dir()
prints
>>> dir()
['__annotations__ ', '__builtins__ ', '__doc__ ', '__loader__ ', '__name__ ', '__package__ ', '__spec__ ']
>>> import xml
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'xml']
With an argument (which needs to represent an
object ,
dir(obj)
reports the object's attributes. In our case, the attributes of
xml
can now be queried with
doc(xml)
:
>>> dir (xml)
['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
Importing a «sub-module» (if this is the correct terminology) does not add anything to the current local scope:
>>> import xml.dom.minidom
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'xml']
However, it is listed in the attribute list of xml
:
>>> dir(xml)
['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'dom']
>>> dir (xml.dom)
['DOMException', 'DOMSTRING_SIZE_ERR', 'DomstringSizeErr', 'EMPTY_NAMESPACE', … etc. etc. … ]
A name can be removed from a namespace with the
del
statement:
>>> del xml
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']