Reputation: 353
The python documentation says:
"One particular module deserves some attention: sys, which is built into every Python interpreter."
My understanding is that if a module is built into the Python interpreter itself, then there is no need for an explicit import statement. If the sys module is built-in the Python interpreter, then why is an explicit import statement required for the sys module?
Upvotes: 4
Views: 459
Reputation: 362786
sys
is imported at Python startup. So when you import sys
, it does not actually do anything except bind a variable name to the already-existing module.
When creating a module instance, there is no reason to have the sys
name bound in the module scope when many (probably most) modules don't need to use sys
. So, that name is not in scope by default.
Upvotes: 3
Reputation: 798706
import
performs two functions:
With "built-in" modules item 1 is not an issue, but item 2 is still important; without it the code would throw a NameError
.
Upvotes: 1