I have a list of files, I want to iterate and import functions from those files, so as to work on them one by one, python
<p>I have a list of files, using command in python <code>from filename import *</code> , works for a single file as I am giving the exact name of the file, but if I want to use it as <code>from list[i] import *</code> to iterate over a list and importing function from files one after the another to  work on it, it doesn't work? what changes should I make so as to use it for a list of files, so that I can easily iterate?</p>

<p>Use <a href="https://docs.python.org/3/library/importlib.html#importlib.import_module" rel="nofollow">importlib</a> for that:</p>

<pre><code>from importlib import import_module

module_list = [import_module("test.mod{}".format(i)) for i in range(20)]

# OR

module_list = []
for i in range(20):
    module_list.append(import_module("test.mod{}".format(i)))
</code></pre>

<p>As stated by the <a href="https://docs.python.org/3/library/functions.html#__import__" rel="nofollow">documentation</a>, <strong>do not use internal things such as <code>__import__</code></strong>.</p>

python file file-handling