Converting String to Class

M

michael

Hello,

I have a script that is called by the shell this way :

mqtrigger.py "TMC 2TEST.QUEUE LV1871.MQPROCESS"

So argv[1] is the string "TMC 2TEST.QUEUE LV1871.MQPROCESS"

I would like to construct a class with that string that contains the
attributes

-StrucId
-VersionId
-QName
-ProcessName

I am thinking about using the following info

opts = [['StrucId', CMQC.MQTMC_STRUC_ID, '4s'],
['Version', CMQC.MQTMC_VERSION_2, '4s'],
['QName', '', '48s'], ## or less :)
['ProcessName', '', '48s']] ## or less :)

1. is the attributename
2. is the default
3. is the format in the string

So the string could be parsed with the opts Info and the attributes
could be inserted into the class. I dont even have a starting point
how to do that. Could somebody point my into the right direction

Regards

Michael
 
M

Matt Gerrans

You didn't specify exactly how the string is parsed, so this is a guess:

class Thingy(object):
def __init__(self,rawinfo):
self.StructId, vq,self.ProcessName = rawinfo.split()
self.Version,self.QName = vq.split('.')
def __str__(self):
return '<Thingy: StructId: %s, Version: %s, QName: %s, ProcessName: %s
>' % (self.StructId, self.Version, self.QName, self.ProcessName)

t = Thingy( "TMC 2TEST.QUEUE LV1871.MQPROCESS" )
str(t) -> '<Thingy: StructId: TMC, Version: 2TEST, QName: QUEUE,
ProcessName: LV1871.MQPROCESS >'

- mfg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,212
Messages
2,571,101
Members
47,695
Latest member
KayleneBee

Latest Threads

Top