Let me explain a little better with some code.
class Opcode (Enum):
WEEK= 1
EMAIL= 2
NAME= 3
DOB= 4
I then have a parameters class which processes data received by the server, and stores it in the appropriate variable :
class parameters:
week = None
email = None
name = None
dob = None
def __init__(self, conn):
#some initialization stuff, irrelevant
def process_input(self, opcode, data):
if opcode == Opcode.WEEK.value:
self.week = data
elif opcode == Opcode.EMAIL.value:
self.email= data
elif opcode == Opcode.NAME.value:
self.name= data
elif opcode == Opcode.DOB.value:
self.dob= data
.
.
.
else :
print("unknown opcode provided. disconnecting ... ")
#disconnect from client ...
This doesn't seem too bad with only 4 opcodes, but in reality my program has 12 opcodes and so this long if...elif...elif...else
branch seems like a bad way of processing inputs. I'm use to working with C++, in which case I'd have used a switch-case, but they don't appear to be a thing in python, so perhaps there is a better solution I just don't know about. Any advice?