I'm trying to interpret data I am planning to send betweeen machines with a chosen target where I will send the data to and the data the following code is supposed to do this(the target is a number of any length and has to start with a "/") I know the whole code isn't great and I am probably using wrong names for pretty much everything but I hope with a bit of help it will work
def Interpret(command):
if(command[0] != "/"):
return "ERROR"
o = 1
targetstr = []
while(command[o] != " "):
targetstr.append[command[o]]
o = o + 1
try:
"".join(targetstr)
target = int(targetstr)
except:
return "ERROR"
data = []
for i in range(o + 1, len(command)):
data.append(command[i])
return [target, "".join(data)]
everytime I run the code I get this error message: targetstr.append[command[o]] TypeError: 'builtin_function_or_method' object has no attribute 'getitem' (pbviously it is supposed to give me an array with the target and the data)
appendis correctly called in one of the two occurrences."".join(targetstr)doesn't do anything useful; it leavestargetstrunchanged while ignoring the return value ofjoin. Did you meantargetstr = "".join(targetstr)? (Also,targets = []would be a better name to use for the list of targets; it's not a string yet.)