help / examples reading floats / doubles, user definded objs

Alex Martelli aleaxit at yahoo.com
Mon Jan 8 11:54:13 EST 2001


"Bryan Webb" <bww00 at amdahl.com> wrote in message
news:93aomd$7nd at dispatch.concentric.net...
> Hi,
>     I'm loolking for examples of reading floats, doubles and user defined
> objects .

'reading' from where?  Sorry, but the question is not clear
to me.  I guess (from the fact that you're drawing a distinction
between 'floats and doubles', which Python itself doesn't draw)
that you have a binary data file, into which some other program
(maybe a C one?) has written some doubles, some floats, and
some other data ('user defined objects') yet?  If that is the
case, the builtin struct module is probably what you want, together
with the .read method of file-objects.

If, on the other hand, what you have in the file are lines of
text, with readable (e.g., ASCII) forms of the data (in which
case, no float/double distinction gets drawn), then you'll most
likely want to use from the file-object is the .readlines method
(just possibly, .readline): it will return strings representing
the textlines in the file, which you'll want to split (depending
on what separators are used), then subjecting each "token" string
to the appropriate conversion-function (e.g., the builtin 'float()').

Maybe we can be of more help if you explain better what you are
trying to do...


Alex






More information about the Python-list mailing list