I encountered an error on Eclipse PyDev AttributeError: '_socketobject' object has no attribute 'getservbyname' with the following code:
from socket import *
help(socket.getservbyname)
I encountered an error on Eclipse PyDev AttributeError: '_socketobject' object has no attribute 'getservbyname' with the following code:
from socket import *
help(socket.getservbyname)
when you are doing a star import, you dont have to append the module name to the method.
try this:
import socket
help(socket.getservbyname)
In case, In case you want to do a star import, which is not recommended because of namespace polluting, this is what you should be doing:
from socket import *
help(getservbyname)
With python, you have three forms of import you can do
import socket
help(socket.getservbyname)
This form imports the whole of the socket module into your code with the same name. You then access things in it from their prefixed name
Next up:
import socket as othersocket
help(othersocket.getservbyname)
This imports the whole of the socket module into your code, but with an alternate name. You then access things from it with the alternate prefixed name
Finally:
from socket import *
# or
from socket import getservbyname
help(getservbyname)
This way, you import just specific bits from the module into your code, with their names without a prefix.
As you can hopefully see, there's a few ways to do it, you just need to be consistent about how you import vs how you use