What happen when you import same module twice or more?
The simple answer in nothing! In python when you import a module and you try to import it again in the same instance of a script it won't work!
That is why when you work with modules such as these listed below, it is easy to get confused that the modules work only the first time you ran them.
- import __hello__
- import this
- import antigravity
You will only see the result of their import once.
import __hello__: will print the famous "Hello World!" as an output.
import this: will print the 'Zen of Python'
import antigravity: will open a browser link to python antigravity xkcdwebcomic.
If you try to run any of the above for the second time, none will work.
Obviouly, I don't see any reason why you will reimport a module. But if you do it for whatever reason, then the second import won't work.
No comments:
Post a Comment