On Jun 8, 6:18?pm, Ben Finney <[EMAIL PROTECTED]> wrote: > Neil Cerutti <[EMAIL PROTECTED]> writes: > > I was hoping for a module that provides a way for me to specify a > > fixed file format, along with some sort of interface for writing and > > reading files that are in said format. > > Isn't that done by the 'struct' module > <URL:http://www.python.org/doc/lib/module-struct>? > > >>> records = [ > ... "Foo 13 Bar ", > ... "Spam 23 Eggs ", > ... "Guido 666Robot ", > ... ] > >>> record_format = "8s3s8s" > >>> for record in [struct.unpack(record_format, r) for r in records]: > ... print record > ... > ('Foo ', '13 ', 'Bar ') > ('Spam ', '23 ', 'Eggs ') > ('Guido ', '666', 'Robot ')
But when you pack a struct, the padding is null bytes, not spaces. > > -- > \ "Buy not what you want, but what you need; what you do not need | > `\ is expensive at a penny." -- Cato, 234-149 BC, Relique | > _o__) | > Ben Finney -- http://mail.python.org/mailman/listinfo/python-list