+ 1

What's the difference between 'import module' and 'from module import ...' considering performance?

What is recommended? Which one should be used more often? What does it depend on? How to decide...

10th Nov 2020, 2:15 PM
Orville Vroemen
Orville Vroemen - avatar
3 Antworten
+ 1
The difference is that "from <module/file> import <class/module>" is used for importing some specific thing from that file/module. In the other hand "Import<module> is used for importing the whole module/file.
10th Nov 2020, 2:27 PM
yo129
yo129 - avatar
+ 1
Thanks Aryan Sarpal, but what I meant is how it impacts the performance of the program. Do you know? Edit: I assume that if you use huge modules, it's better to avoid loading them all into the program. But I'm not sure, so I asked
10th Nov 2020, 3:00 PM
Orville Vroemen
Orville Vroemen - avatar
+ 1
Hi Orville Vroemen, the performance will impact while running the file but it might be that when you are using the "from import" one the class/module you are importing might be that it needs the whole module to run that part of the module. So it matters where and when you need what.
17th Nov 2020, 11:45 AM
yo129
yo129 - avatar