.Re: scanf string in python

Robert L. No_spamming at noWhere_7073.org
Fri Apr 21 03:14:50 EDT 2017


> > I have a string which is returned by a C extension.
> >
> > mystring = '(1,2,3)'
> >
> > HOW can I read the numbers in python ?
> 
> re.findall seems the safest and easiest solution:
> 
> >>> re.findall(r'(\d+)', '(1, 2, 3)')
> ['1', '2', '3']
> >>> map(int, re.findall(r'(\d+)', '(1, 2, 3)'))
> [1, 2, 3]


'(1,2,3)'.scan(/\d+/).map &:to_i

 ===>
[1, 2, 3]

-- 
[T]he attackers tore off the woman's clothes and raped her until five others
arrived....  The new arrivals took turns having sex with her and then sodomized
her....  At gunpoint, the assailants forced the mother and son to have sex.
www.sun-sentinel.com/local/palm-beach/sfl-flpdunbar0822nbaug22-story.html



More information about the Python-list mailing list