scanf string in python

Bengt Richter bokr at oz.net
Fri Jul 18 22:15:05 CEST 2003


On Thu, 17 Jul 2003 22:37:07 -0700, Erik Max Francis <max at alcyone.com> wrote:

>lehrig wrote:
>
>> 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]
>
Did you use the regex parens for a reason I am unaware of?

 >>> import re
 >>> re.findall(r'(\d+)', '(1, 2, 3)')
 ['1', '2', '3']
 >>> re.findall(r'\d+', '(1, 2, 3)')
 ['1', '2', '3']

Regards,
Bengt Richter




More information about the Python-list mailing list