python <class ‘module’>

Reading Time: < 1 minute

Last updated: 5/12/2024

Python dir() FunctionThe dir() function returns all properties and methods of the specified object, without the values.

In short, sometimes it is very useful to at least understand the “handles” that exist when you are given a black box.

M:\>python<br>Python 3.12.3 (tags/v3.12.3:f6650f9, Apr  9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import warnings
>>> dir(warnings)
['WarningMessage', '_DEPRECATED_MSG', '_OptionError', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_add_filter', '_defaultaction', '_deprecated', '_filters_mutated', '_formatwarning_orig', '_formatwarnmsg', '_formatwarnmsg_impl', '_getaction', '_getcategory', '_is_filename_to_skip', '_is_internal_filename', '_is_internal_frame', '_next_external_frame', '_onceregistry', '_processoptions', '_setoption', '_showwarning_orig', '_showwarnmsg', '_showwarnmsg_impl', '_warn_unawaited_coroutine', 'catch_warnings', 'defaultaction', 'filters', 'filterwarnings', 'formatwarning', 'onceregistry', 'resetwarnings', 'showwarning', 'simplefilter', 'sys', 'warn', 'warn_explicit']
>>>> print(type(warnings))
<class 'module'>
>>>


In this example, perhaps you are using pandas module. And perhaps you feel that the concat function is a bit too chatty recently. You don’t need to warn me in the future that there may be impending dire, and doom because an element may or may not be n/a. If you would be so kind just to do the work (quietly) … I would be most appreciative.

import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
This entry was posted in Programming, Python. Bookmark the permalink.