[issue4438] Add an easy way to __import___ submodules

Mart Sõmermaa report at bugs.python.org
Wed Nov 26 15:23:59 CET 2008


Mart Sõmermaa <mrts at mrts.pri.ee> added the comment:

Attached is a naive proof-of-concept implementation (that breaks things,
i.e. the real implementation should strive for better
general compatibility), but works as expected:

>>> __import__('imprt.foo.foo', submodule=True)
<module 'imprt.foo.foo' from 'imprt/foo/foo.py'>

>>> __import__('imprt.foo.foo', submodule=False)   
<module 'imprt' from 'imprt/__init__.py'>

>>> __import__('imprt.foo.foo')
<module 'imprt' from 'imprt/__init__.py'>

# Die on unexpected arguments like strings, lists etc to
# avoid confusion
>>> __import__('imprt.foo.foo', submodule='z')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required

----------
keywords: +patch
Added file: http://bugs.python.org/file12136/issue4438.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4438>
_______________________________________


More information about the Python-bugs-list mailing list