In Python, the dir()
function is used to display a list of attributes, classes, methods of the argument which is passed in to it, right ?
For example there is a module email
in python
import email
dir(email)
Result:
['Charset', 'Encoders', 'Errors', 'FeedParser', 'Generator', 'Header', 'Iterators', 'LazyImporter', 'MIMEAudio', 'MIMEBase', 'MIMEImage', 'MIMEMessage', 'MIMEMultipart', 'MIMENonMultipart', 'MIMEText', 'Message', 'Parser', 'Utils', '_LOWERNAMES', '_MIMENAMES', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', '_name', 'base64MIME', 'email', 'importer', 'message_from_file', 'message_from_string', 'mime', 'quopriMIME', 'sys']
So what I want to know is how to tell whether a given object in the above list is an attribute, method, class, or function.
From the above list, we can expect that __all__
, __builtins__
, __doc__
, etc. are attributes, but how can we differentiate all/remaining of these types just by looking at the list?