Here's a puzzle...
paulsid at home.com
Sat Jul 21 21:06:24 EDT 2001
> print data[len(sender)+2:string.find(data[len(sender)+2:],' ')]
> And if you are up to it, feel free to help me splice (correct terminology,
> parse?) for variables rcpt and message ;)
By any chance are you coming from a C background? :-) That's a nasty
one-liner, so I'm not even going to attempt to figure out how it works.
Instead, here is a much nicer way to do this kind of thing:
(This assumes the format is always the same, i.e. colons prefix each
section and single spaces separate the first three variables.)
"""Returns a tuple: (sender, command, rcpt, message)"""
tmp = data.split(':')
hdr = tmp.split(' ')
return (hdr, hdr, hdr, tmp)
If you have this in a module called parsemsg you can use it like this:
>>> teststring = ":Angel PRIVMSG Wiz :here is my message!"
>>> import procmsg
>>> sender, command, rcpt, message = parsemsg.parsemsg(teststring)
>>> print sender
>>> print command
>>> print rcpt
>>> print message
here is my message!
Hope that helps.
Paul Sidorsky Calgary, Canada
paulsid at home.com http://members.home.net/paulsid/
More information about the Python-list