Converting a text data file from positional to tab delimited.
Emile van Sebille
emile at fenx.com
Tue Mar 13 11:33:06 EST 2001
I was in the mood for some obfustication this morning:
(Note: this will wrap. there are three lines, one each for srceRecs,
fldmap and converted)
srceRecs = "aaabbbccc\nddd111222\n333444eee\n"
fldmap = [('fld1',0,3),('fld2',3,6),('fld3',6,9)]
converted = [ "".join ( [x + ['', '\t'][0 + z in [ p[2]-1 for p in
fldmap ] ] for x, z in map(None, list(srcerec) ,xrange(fldmap[-1][-1])) ])
for srcerec in srceRecs.split('\n')[:-1] ]
FWIW,
didn't-get-what-I-really-wanted-ly y'rs ;-)
Emile van Sebille
emile at fenx.com
More information about the Python-list
mailing list