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

Yes, but in this case the OP expects to get ['A',1,3.0]

A shorter version :

def parseline(line,format):
    xlat = {'x':None,'s':str,'f':float,'d':int,'i':int}
    result = [ xlat[f](w) for f,w in zip(format,line.split())
        if xlat.get(f,None) ]
    if len(result) == 0: return None
    if len(result) == 1: return result[0]
    return result

Pierre

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to