I saw the code from Youtube and have a question.
The code below imports time
twice.
import pandas as pd
import os
import time
from datetime import datetime
from time import mktime
By importing time on third line, I think 5th line is useless.
Why does he import time twice?
If multiple modules imports the same module then angular evaluates it only once (When it encounters the module first time). It follows this condition even the module appears at any level in a hierarchy of imported NgModules.
The rules are quite simple: the same module is evaluated only once, in other words, the module-level scope is executed just once. If the module, once evaluated, is imported again, it's second evaluation is skipped and the resolved already exports are used.
For efficiency reasons, each module is only imported once per interpreter session. Therefore, if you change your modules, you must restart the interpreter – or, if it's just one module you want to test interactively, use importlib.reload() , e.g. import importlib; importlib.reload(modulename) .
So each module is imported only one time. To better understand import mechanics I would suggest to create toy example. So import really happens only once. You can adjust this toy example to check cases that are interesting to you.
Why does he import time twice?
He doesn't. He copies time.mktime
to mktime
. He doesn't have to, he just does so for convenience.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With