August 14th, 2013, 10:21 PM
I'm looking at some code examples for sockets, and find one example that shows:
and another that shows:
from socket import *
I don't understand the difference, and find that I can't do both because in one condition the 'import socket' instruction works for one example, but if I do both imports, it no longer works. Can someone please tell me what's going on here.
August 14th, 2013, 11:53 PM
The first is a standard import.
anytime you want something from that module you have to qualify it with the module name; ie:The star import on the other hand
dumps the entire contents of the module into your global namespace and you could access all of its contents unqualified.
from module import *
Star imports are bad; especially for neophytes that don't understand why they are bad. Don't use them and try to avoid any tutorials that do. It is much easier to never start using than to quit once already addicted.