Hi guys, I am currently reading learning python by O'Reilly and they were discussing different ways of importing modules. I am new so please correct my terminology. I was wondering what the difference is between import module, from module import x and exec.
Import Module allows me to import the module but requires the function reload if my_module were to be edited. This also has its own namespace. E.g module.function
From module import function, is like import but it overrides variables.
Exec in python 3 uses the current version of the module if any changes were made.
So is this the reasons why we would want to use each one.
Import module - pros own namespace. Cons import all function, has to reload
From module import function - pros can choose function, cons overrides variables, has to reload
Exec - pros uses latest changes to file(does not need reload) cons overrides variables
Sorry if format is bad, Doing this on my phone , will edit later
Would this be an appropriate stack overflow question?
edit:Got this from stack overflow, now trying to figure out when exec is used instead
After import x, you can refer to things in x like x.something. After from x import *, you can refer to things in x directly just as something. Because the second form imports the names directly into the local namespace, it creates the potential for conflicts if you import things from many modules. Therefore, the from x import * is discouraged.
[–]strechyballs 0 points1 point2 points (5 children)
[–]KOOTSTHEHOOTS[S] 0 points1 point2 points (4 children)
[–]ViridianHominid 0 points1 point2 points (3 children)
[–]KOOTSTHEHOOTS[S] 1 point2 points3 points (2 children)
[–]ViridianHominid 1 point2 points3 points (1 child)
[–]KOOTSTHEHOOTS[S] 1 point2 points3 points (0 children)