__import__ is stupid.

Does anyone else think __import__ is completely ridiculous? I always end up wrapping it to do what I want.

Example:
>>> from os import path
>>> path
<module 'posixpath' from '/usr/lib/python2.4/posixpath.pyc'>
>>> mod = __import__('os', locals(), globals(), ['path'])
>>> mod
<module 'os' from '/usr/lib/python2.4/os.pyc'>
>>> mod.path
<module 'posixpath' from '/usr/lib/python2.4/posixpath.pyc'>
>>> mod = __import__('os')
>>> mod
<module 'os' from '/usr/lib/python2.4/os.pyc'>
>>> mod.path
<module 'posixpath' from '/usr/lib/python2.4/posixpath.pyc'>
>>>

When I tell __import__ to get 'path' from 'os' it gives me 'os'. If I wanted that, why would I have passed it a from list with ['path'] in it? Seriously, guys. How can this be considered reasonable behavior?

No comments:

Post a Comment