Help me refresh my Python memory on how to do this

Carsten Gaebler cg at schlund.de
Mon Apr 2 11:14:56 EDT 2001


Kemp Randy-W18971 wrote:
> I have a text file, and for simplicity sake, I will only put in two entries
> 
> Min. line width (mils):                 4
> 4.00 mils trace segment count / % of total:    5598/80.10 %
> 
> I wish to parse this input file and just output the numbers in a separate text file, like so
> 4
> 5598
> 80.10
> 
> I think I will need the split function, but what is the simplest way to accomplish this?


Try the split() function from the re module:

>>> import re
>>> s = "4.00 mils trace segment count / % of total:    5598/80.10 %"
>>> re.split(r'[^\d.]+', s)
['4.00', '5598', '80.10', '']
>>> 


cg.



More information about the Python-list mailing list