Difference between import and __import__ in Python

python, python-import

Solution

import dataFile 

translates roughly to

dataFile = __import__('dataFile')

Apparently the developer decided that they wanted to use strings to identify the modules they wanted to import. This is presumably so they could dynamically change what module they wanted to import ...

Problem

I was taking a look at some commit of a project, and I see the following change in a file: ``` - import dataFile + dataFile = __import__(dataFile) ``` The coder replaced `import dataFile` by `dataFile = __import__(dataFile)`. What exactly is the difference between them?

Original source