scanf string in python

Erik Max Francis max at alcyone.com
Fri Jul 18 01:37:07 EDT 2003


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]

Flavor to taste.

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ You can buy any kind of love, but you can't buy love deluxe.
\__/  Sade Adu




More information about the Python-list mailing list