'import' vs. 'from .. import' in Python: Which uses more memory?

preview_player
Показать описание
Python offers us two ways to import modules: We can use the "import" statement to load an entire module, or "from...import" to define specific names. The question is: Does "from...import" save memory, because it's only loading specific names?

Рекомендации по теме
Комментарии
Автор

Thanks for the explanation. I create a lot of projects on my Raspberry Pi and I was looking for anything that could improve the performance when starting a program. This discovery is very disappointing but I am very thankful you showed me that this is no longer an angle worth exploring when optimizing.

FerretYourFace
Автор

Man... that was a big mistake from my part! Thanks for the advice!

walkdead
Автор

This is great explanation! Thanks for this tutorial

zacky
Автор

Hi Reuven!

Very nice video, thank you!

With then Zen of Python ("Explicit is better than implicit") in mind, wouldn't it be better to use "import random" and "random.randint(...)" for the sake of clarity as to where the randint function is defined? Using "from random import randint" saves some typing, but is not as clear, particularly when you use modules that do not belong to the standard library.

andreasjanzen
Автор

This is very useful information, thanks a lot man ; )
+1 like and subscriber

sherzodbekesanov
Автор

Thank you for this very insightful video.
Still I am struggling to understand the difference between:
import datetime
import datetime.timedelta
from datetime import timedelta
and why only the 3rd one works?? same for the similar modules.

poordelir
Автор

What if you have multiple files in your mymod and importing first file using "from" does also imports other files?

ThipuVaasan
Автор

Take my subscription

You'll be getting another watch from me.

vividvault
Автор

I thought I knew the answer to that... I was wrong 🤣

mistwire
Автор

hmm.. but even if it is "from mymod import hello", Python is going from the Top to bottom. The fact that we are not seeing variables in the o/p is that they are not in the print(), but doesnot mean that Python is ignoring them.. Any thoughts on this? We should test out when we do "from mymod import hello" but try to print the mymod.x using print(mymod.x) then if we are seeing the o/p that means Python is reading all the variables and other parts of the code even if we try to import only one function.

kjsk
Автор

From the above explanation, I guess using import package or from package import module uses same memory.

shyamprasad
Автор

What's the difference between import And import*

srinithia
join shbcf.ru