Difference between import and __import__ in Python

I looked through some project commits, and I see the following change in the file:

-       import dataFile
+       dataFile = __import__(dataFile)

The encoder is replaced import dataFileby dataFile = __import__(dataFile).

What is the difference between the two?

+5
source share
1 answer
import dataFile 

carried over to

dataFile = __import__('dataFile')

Obviously, the developer decided that they want to use strings to identify the modules that they wanted to import. This is apparently the case so that they can dynamically change which module they want to import ...

+5
source

All Articles