The difference between import and from import module under python

When importing a module, the module will be loaded into the memory. When a program uses import to import the module again, it will directly use the module that has been loaded in the memory. If the first time importing the module modifies the data of the module, then the second time When importing a module, it will be the modified module

When importing a module from, the module will be loaded into the memory. When a program uses from to import the module again, it will open up space in the memory to import the module again. If the module data is modified by the first import of the module, then the second import of the module will not be the modified module when

in conclusion:

When multiple programs need to import a module at the same time and all access, using import can save memory space

When multiple programs need to import a module at the same time and one of them needs to modify the module, the program of the modified module should use from to import the module.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324550997&siteId=291194637