For homework I am re-implementing the socket class in python. I am not however, well versed in python. I have a question on syntax.
From the python API when you define a socket you use:
import socket
mySocket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM))
However, I don’t know how to define constants that behave life AF_INET and SOCK_DGRAM.
import mySocket
mySocket = mySocket.socket(mySocket.AF_INET,mySocket.SOCK_DGRAM))
gives the following errors
Undefined variable from import: AF_INET
Undefined variable from import: SOCK_DGRAM
The mySocket class currently looks like:
class socket:
AF_INET;
SOCK_DGRAM;
def socket(.....
You need to define the constants at module level, not in your
socketclass: