__import__(name, fromlist=...), was Re: Shuffle

Peter Otten __peter__ at web.de
Mon Sep 15 10:30:50 EDT 2014


Steven D'Aprano wrote:

> A serious question -- what is the point of the fromlist argument to
> __import__? It doesn't appear to actually do anything.
> 
> 
> https://docs.python.org/3/library/functions.html#__import__

It may be for submodules:

$ mkdir -p aaa/bbb
$ tree
.
└── aaa
    └── bbb

2 directories, 0 files
$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> __import__("aaa").bbb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'bbb'
>>> __import__("aaa", fromlist=["bbb"]).bbb
<module 'aaa.bbb' (namespace)>





More information about the Python-list mailing list