[BangPypers] packing floating data
Anand Balachandran Pillai
abpillai at gmail.com
Mon May 31 15:05:33 CEST 2010
On Mon, May 31, 2010 at 6:22 PM, murugadoss <murugadoss2884 at gmail.com>wrote:
> When i pack and unpack, i am able to get real part of the float number. can
> anyone please tell me, how i can pack both the real and imaginary part. Do
> need to split n store the values ??
You seem to keep posting without taking the hints. Noufal's reply
was to try and lead you to the answer which is the Python documentation
on formatting for struct.pack method.
Please don't expect answers to be presented on a platter. All of us
are very nice and all that, but if you have habit (as you seem to) of
posting basic questions without looking it up yourselves first, it
gets a bit tiresome pretty soon.
In this case you need to use 'f' as format character.
>>> s=struct.pack('f', 45.90)
This is mentioned quite clearly in struct module's documentation
- Have you ever tried to see that ?
> Thanks & Regards
> On Mon, May 31, 2010 at 9:14 PM, Noufal Ibrahim <noufal at gmail.com> wrote:
> > On Mon, May 31, 2010 at 5:34 PM, murugadoss <murugadoss2884 at gmail.com>
> > wrote:
> > > Hi all,
> > >
> > > I am trying to pack a float value like 45.90,43.78,543.87. i am using
> > > struct.pack( ) function. When i unpack (using struct.unpack) and print
> > i
> > > am getting only real part of the number.
> > >
> > > Type of the variable is long,
> > > var = 45.90
> > > data = struct.pack("!l",float(var))
> > http://docs.python.org/library/struct.html#format-characters
> > --
> > ~noufal
> > http://nibrahim.net.in
> > _______________________________________________
> > BangPypers mailing list
> > BangPypers at python.org
> > http://mail.python.org/mailman/listinfo/bangpypers
> BangPypers mailing list
> BangPypers at python.org
More information about the BangPypers