problem with split
hanumizzle
hanumizzle at gmail.com
Sat Oct 7 00:33:25 EDT 2006
On 6 Oct 2006 21:07:43 -0700, Eric_Dexter at msn.com <Eric_Dexter at msn.com> wrote:
> I want comment returned in an array and instr_number returned in an
> array.
Let me see if I understand what you want: if there is a line that
starts with instr (best tested with line.startswith('instr') :)), you
want the number and the commen afterwards. I used regexes for this
purpose. In your case:
import re
<snip>
if line.startswith('instr'):
p = re.compile(r'(\d+)\s+;(.*)$')
m = p.search(line)
return (m.group(1), m.group(2))
I returned a tuple of course; you may wish to change that.
BTW, thank you -- I just learned how to use re's in Python.
More information about the Python-list
mailing list