19
loading...
This website collects cookies to deliver better user experience
__call__
” method.socket
” module name as a function, Python will throw TypeError: ‘module’ object is not callable.#Importing the socket module in Python
import socket
#Calling the os module as a function
s = socket(socket.AF_INET, socket.SOCK_STREAM)
print(s)
Traceback (most recent call last):
File "c:\Projects\Tryouts\Python Tutorial.py", line 2, in <module>
s = socket(socket.AF_INET, socket.SOCK_STREAM)
TypeError: 'module' object is not callable
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print(s)
from socket import *
s = socket(AF_INET, SOCK_STREAM)
print(s)
<socket.socket fd=444, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0>
def namemodule():
name='Chandler Bing'
print(name)
import namemodule
print(namemodule())
from namemodule import namemodule
print(namemodule())
# Output
# Chandler Bing