parse-ing? how does it work?
Shaun
shogan at iel.ie
Wed May 24 10:56:30 EDT 2000
i put this.........
> import string
>
> class MessageFormatError:
> def __init__(self, value):
> self.value = value
> def __str__(self):
> return self.value
>
> class Message:
> def __init__(self, messageStr):
> (idStr, subIdStr, nvSeqStr) = string.split(messageStr, None, 2)
>
> try:
> self.id = int(idStr)
> self.subId = int(subIdStr)
> except ValueError:
> raise MessageFormatError("Can't parse: %s" % messageStr)
>
> self.nvSeq = parseNvSeq(nvSeqStr)
>
> def parseNvSeq(nvSeqStr):
> if len(nvSeqStr) == 0:
> return None
> else:
> return nvSeqStr # decode here...
>
......code in a module called findx.py, and heres what happened
>>> from findx import *
>>> m = Message("123 234 This is an nvSeqStr.")
Traceback (innermost last):
File "<pyshell#1>", line 1, in ?
m = Message("123 234 This is an nvSeqStr.")
File "C:\Program Files\Python\Tools\idle\findx.py", line 19, in __init__
self.nvSeq = parseNvSeq(nvSeqStr)
NameError: parseNvSeq
>>>
ive tried moving and changing loads of ways but i cant get it to work,
parseNvSeq seems to be the main problem, would
ye be able to tell me whats wrong? please..
thanks
Shaun
_____________________________________________________
my original problem:
ok,
i have variables ,id ,subId, nvSeqStr
a message will be passed in like...(some code & pseudo code below)
forgive me im still a newbie and i cant grasp this stuff at all....
class message:
import string
def __init__(self, id, subId, nvSequence):
self.id=id
self.subId=subId
self.nvSequence=nvSequence()
#overloaded constructor 1
#sets up member vars id and subId subId of type int
def __init__(self, id, subId, nvSequence=None):
self.id = id
self.subId = subId
self.nvSequence = nvSequence
def Message(StringMsg):
# what i want to do is,
1) find the index of the first integer in the string StringMsg
2) #on an error throw a format exception
3) save int in var id
4) find the index of the second integer in the string StringMsg
#on an error throw a format exception
save int in var subId
5) keep the rest of the string in var nvSeqStr
6) if nvSeqStr is not empty
7) try
decode it
#on an error throw a format exception
8) else
set nvSeqStr to null
#on an error throw a format exception
=====================
Shaun Hogan
Interactive Enterprise Ltd.
alt. E-mail : shaun_hogan at yahoo.com
Phone: +353 86 8342529
The University of Limerick Rollerhockey Club
URL: http://rollerhockey.csn.ul.ie
More information about the Python-list
mailing list