How to extract 2 integers from a string in python?

Cameron Laird claird at lairds.us
Fri Jun 9 16:53:26 CEST 2006


In article <e6b02t$2u2$1 at minji.szn.dk>,
Klaus Alexander Seistrup  <klaus at seistrup.dk> wrote:
>yinglcs at gmail.com skrev:
>
>> how can I extract 2 integers from a string in python?
>>
>> for example, my source string is this:
>> Total size: 173233 (371587)
>>
>> I want to extract the integer 173233 and 371587 from that 
>> soource string, how can I do that?
>
>E.g.:
>
>#v+
>
>>>> import re
>>>> re.findall(r'\d+', 'Total size: 173233 (371587)')
>['173233', '371587']
>>>> 
			.
			.
			.
Nicely expressed.

People doing a lot of report-scraping might also want to
consider one of the scanf implementations for Python. 
<URL: http://hkn.eecs.berkeley.edu/~dyoo/python/scanf/ >
has an example.



More information about the Python-list mailing list