Discussion:
[Tutor] About Python Module to Process Bytes
Michelle Meiduo Wu
2015-08-04 16:26:16 UTC
Permalink
Hi there,
I'd like to find some python module to easily process bytes array data, like encoding different types of data (char, long, short, float, etc) into a same bytes array. I checked Python built-in library and there are bytes and bytearray types which don't provide enough functions for processing bytes easily.
Does anybody know if there is other convenient module available for processing bytes?
Thank you,Michelle
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Danny Yoo
2015-08-04 19:12:20 UTC
Permalink
On Tue, Aug 4, 2015 at 9:26 AM, Michelle Meiduo Wu <***@hotmail.com> wrote:
> Hi there,
> I'd like to find some python module to easily process bytes array data, like encoding different types of data (char, long, short, float, etc) into a same bytes array. I checked Python built-in library and there are bytes and bytearray types which don't provide enough functions for processing bytes easily.
> Does anybody know if there is other convenient module available for processing bytes?


The 'struct' module is probably what you're looking for. See:

https://docs.python.org/3.5/library/struct.html

Let us know if you have any questions with it. Good luck.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Michelle Meiduo Wu
2015-08-05 03:51:28 UTC
Permalink
I think this works for me!
Thanks a lot,Michelle

> From: ***@hashcollision.org
> Date: Tue, 4 Aug 2015 12:12:20 -0700
> Subject: Re: [Tutor] About Python Module to Process Bytes
> To: ***@hotmail.com
> CC: ***@python.org
>
> On Tue, Aug 4, 2015 at 9:26 AM, Michelle Meiduo Wu <***@hotmail.com> wrote:
> > Hi there,
> > I'd like to find some python module to easily process bytes array data, like encoding different types of data (char, long, short, float, etc) into a same bytes array. I checked Python built-in library and there are bytes and bytearray types which don't provide enough functions for processing bytes easily.
> > Does anybody know if there is other convenient module available for processing bytes?
>
>
> The 'struct' module is probably what you're looking for. See:
>
> https://docs.python.org/3.5/library/struct.html
>
> Let us know if you have any questions with it. Good luck.

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Jerry Hill
2015-08-04 19:19:57 UTC
Permalink
On Tue, Aug 4, 2015 at 12:26 PM, Michelle Meiduo Wu <***@hotmail.com> wrote:
> Hi there,
> I'd like to find some python module to easily process bytes array data, like encoding different types of data (char, long, short, float, etc) into a same bytes array. I checked Python built-in library and there are bytes and bytearray types which don't provide enough functions for processing bytes easily.
> Does anybody know if there is other convenient module available for processing bytes?

You're probably looking for the struct module:
https://docs.python.org/3/library/struct.html

--
Jerry
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Steven D'Aprano
2015-08-05 02:24:37 UTC
Permalink
On Tue, Aug 04, 2015 at 12:26:16PM -0400, Michelle Meiduo Wu wrote:

> Hi there,
> I'd like to find some python module to easily process bytes array
> data, like encoding different types of data (char, long, short, float,
> etc) into a same bytes array. I checked Python built-in library and
> there are bytes and bytearray types which don't provide enough
> functions for processing bytes easily. Does anybody know if there is
> other convenient module available for processing bytes?

Others have suggested the struct module, but you might also mean the
array module:

py> from array import array
py> array('B', [100, 200, 255]) # Unsigned bytes
array('B', [100, 200, 255])
py> array('B', [100, 200, 256]) # 256 overflows
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: unsigned byte integer is greater than maximum


https://docs.python.org/3/library/array.html
https://docs.python.org/2/library/array.html


--
Steve
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Loading...