Hi, i'm having some trouble using the built-in apply function. I want to take a string in an external definition then apply definitions on it which are in a class.
The code I have is:
global msgstr
def create_message(message, msgstr):
if msgstr[0:3].upper() == 'CMD':
return apply(message, (msgstr))
elif msgstr[0:3].upper() == 'RSP':
return apply(message, (msgstr))
elif msgstr[0:3].upper() == 'IND':
return apply(message, (msgstr))
elif msgstr[0:3].upper() not in 'CMDRSPIND':
print "Miscellaneous message has been found with details", msgstr
else:
pass
class message(object):
def __init__(self, msgstr):
self.msgstr = msgstr
def getdetails(self):
print "Type: ", msgstr[0:3]
print "Date Stamp: ", msgstr[9:11],"/",msgstr[7:9],"/",msgstr[3:7]
I'm taking in a string, for example CMD20090114:1 which I want to apply the function getdetails on. I input:
teststr="CMD20090114:1"
m=create_message(message, teststr)
m.getdetails()
It returns an error saying global name 'msgstr' is not defined
Can someone tell me where I'm going wrong.
Thanks