paseline(my favorite simple script): does something similar exist?

Istvan Albert istvan.albert at gmail.com
Thu Oct 12 15:26:06 EDT 2006


RickMuller wrote:
> One of my all-time favorite scripts is parseline, which is printed

here is another way to write that:

def parseline(line, format):
     trans  = {'x':lambda x:None,'s':str,'f':float,'d':int,'i':int}
     return [ trans[f](w) for f,w in zip(format, line.split() ) ]

>>> parseline( 'A 1 22 3 6', 'sdxf')
['A', 1, None, 3.0]


I.




More information about the Python-list mailing list