Stuart Prescott <[email protected]> writes:
>
> Any opinions on whether it should return the data unparsed as
>
> source_package (version)
>
> or whether it should be clever enough to return a
>
> namedtuple(..., ['source', 'version'])
>
Hmm. I'm not (blush) familiar with named tuples. I was thinking
something simple-minded like the following. By all means feel free to do
the pythonic thing though.
import re
rex=re.compile('([^(\s]+)\s*[(]([^)]+)[)]$')
def parse_source(string):
matches=rex.match(string)
if matches:
return (matches.group(1),matches.group(2))
else:
return string
def test_parse_source_without():
assert parse_source('0xffff') == '0xffff'
def test_parse_source_with():
assert parse_source('0xffff (0.8-1)') == ('0xffff','0.8-1')
--
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/pkg-python-debian-maint