[Tutor] Puzzled

ammar azif ceasar102 at yahoo.com
Sat Aug 30 00:15:19 CEST 2008

Thanks for the explanation. Btw, How can I get the size of python primitive data types in bytes? Is it defined somewhere in a file that I can look at? 

--- On Fri, 8/29/08, Kent Johnson <kent37 at tds.net> wrote:
From: Kent Johnson <kent37 at tds.net>
Subject: Re: [Tutor] Puzzled
To: ceasar102 at yahoo.com
Cc: tutor at python.org
Date: Friday, August 29, 2008, 4:41 PM

On Fri, Aug 29, 2008 at 5:13 PM, ammar azif <ceasar102 at yahoo.com> wrote:
> I wrote a python program that used time() function from the time module to
> retrieve time in seconds since Epoch. After the value was retrieved which
> checked is a float by using type(),  the value was then written into a
> in binary format. Then another C program that I wrote opened the file and
> converted the value into a time_t variable but it was totally different
> the correct value. Then I found that the time_t size is actually 4 byte
> integer which is not the same with 8-byte float value returned by
> time.time(). Why is this so? Being written with C library, isn't
> suppose to work well with it?

The C time_t type is very loosely specified; in ANSI C it is only
required to be an arithmetic type. According to Wikipedia
(http://en.wikipedia.org/wiki/Time_t), Posix-compliant systems still
have latitude to implement it as 32 or 64 bits.

Python tries to be bit higher level, giving you fractional seconds if
the implementation supports it and a common data type across
implementations. So there is not an exact match in functionality.

If you want to write data to file in a format that can be read by
another program, you should look at the struct module.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080829/2594970d/attachment-0001.htm>

More information about the Tutor mailing list