11. Here Be Dragons


#1

Can anyone explain me what was 11 about, i don't fully understand it.
From what i understood it's better to only import the functions we need because importing an entire module overwhelms the program. Is that right?


#2

Think about this way, when a program runs it uses a certain amount of memory let's give that a number,

memory = 100%

lets assume that you use the import all method and take up about 25% if your program is running about 2 to 3 loops that there needs to be memory enough to handle those processes. Now if you only need the time module and you imported that module alone let's assume it takes up only about 0.1% now you'll have much more memory for your interpreter to allocate to the processes that require it. :slight_smile:


#3

Hi @netsolver98858

The "Here Be Dragons" course you're describing teaches the pitfalls of universal imports, such as import Math. The provided code shows first importing the math module, then assigning a variable (everything) to the full contents of the math module. Then, it prints everything out. Here's the output:

['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']

That's the entire contents of our math module. This takes up a HUGE amount of unnecessary memory. However, it's very unlikely that you'll be using all of these, if even more than one, in a program. This lesson teaches the necessity to only import certain parts of modules. So instead of importing everything like this lesson does using import math we can import what we specifically want, like the sqrt function. Read over the lesson information on the sidebar, it should help answer anything else. If not, feel free to ask any more questions. Hope this helps.


#4

That's what i tought, i just needed to be sure.
Thank you!


#5

Thank you for making it clear, English isn't my first language so i wasn't sure.


#6

You're most welcome :slight_smile:


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.