Working with fixed format text db's
Ben Finney
bignose+hates-spam at benfinney.id.au
Fri Jun 8 19:18:19 EDT 2007
Neil Cerutti <horpner at yahoo.com> 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 ')
--
\ "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
More information about the Python-list
mailing list