[Python-Dev] Steroidal builtins (was: Possible optimization for LOAD_FAST ?)

skip at pobox.com skip at pobox.com
Wed Jan 5 01:10:35 CET 2011

    Steven> I've been known to monkey-patch builtins in the interactive
    Steven> interpreter and in test code.

Me too.  I use a slightly beefed up dir() funcion which identifies modules
within a package which haven't been imported yet.  Handy for quick-n-dirty

    >>> import email
    >>> dir(email)
    ['Charset', 'Encoders', 'Errors', 'FeedParser', 'Generator', 'Header',
    'Iterators', 'LazyImporter', 'MIMEAudio', 'MIMEBase', 'MIMEImage',
    'MIMEMessage', 'MIMEMultipart', 'MIMENonMultipart', 'MIMEText',
    'Message', 'Parser', 'Utils', '[_parseaddr]', '[base64mime]',
    '[charset]', '[encoders]', '[errors]', '[feedparser]', '[generator]',
    '[header]', '[iterators]', '[message]', '[parser]', '[quoprimime]',
    '[test/]', '[utils]', '_LOWERNAMES', '_MIMENAMES', '__all__',
    '__builtins__', '__doc__', '__file__', '__name__', '__package__',
    '__path__', '__version__', '_name', 'base64MIME', 'email', 'importer',
    'message_from_file', 'message_from_string', 'mime', 'quopriMIME', 'sys']

Those names with [...] bracketing the names are submodules or subpackages of
the email package which haven't been imported yet.


More information about the Python-Dev mailing list