File to dict

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Fri Dec 7 07:22:02 EST 2007


mrkafk at gmail.com a écrit :
> Hello everyone,

(snip)

> Say, I would like to transform a file containing entries like
> the following into a list of lists with doublecolon treated as
> separators, i.e. this:
> 
> tm:$1$aaaa$bbbb:1010:6::/home/owner1/imap/domain1.tld/tm:/sbin/nologin
> 
> would get transformed into this:
> 
> [ ['tm', '$1$aaaa$bbbb', '1010', '6', , '/home/owner1/imap/domain1.tld/
> tm', '/sbin/nologin'] [...] [...] ]

The csv module is your friend.




More information about the Python-list mailing list