123456789 |
# -*- coding: utf-8 -*- import socket print "Creating socket" s = socket.socket (socket.af_inet, socket. SOCK_STREAM) print "done!" print "connecting to Remote host " s.connect (( , 80 )" print "Done" |
When Python uses the Socket.af_inet constant after using the import socket, this constant is not found in the module, it is strange to check the Internet, the Python import module will be imported according to the name of the file, My Python script file name happens to be socket.py, which causes the imported socket to be wrong, try not to make your own Python script and module the same name, and pay attention to the other file name and module name in the same folder conflict
This article is from the "SANR" blog, please be sure to keep this source
The above for my Baidu out of the results, and then I re-create a file to run the above code, or wrong, why?
That's right.... I did not delete the previous one, after the deletion of the normal ...
Remember not to use the module name after import to name the document ...
"Python" socket programming constant Error problem-1 ' af_inet ' ERROR