(Apr-27-2017, 04:34 AM)Skaperen Wrote: but...... can it be used with non-byte stuff?
In [7]: array.array('I', 'Skaperen'.encode()) Out[7]: array('I', [1885432659, 1852142181]) In [8]:IMHO,
struct
and array
are the tools to process stream data - like if you want to parse a protocol packet. Otherwise, you have to invent bells and whistle...Here's a little more involved example with
struct
- split string into unequal-size fieldsIn [15]: struct.unpack('2h2b2s', b'Skaperen') Out[15]: (27475, 28769, 101, 114, b'en') In [16]:But you have to type-cast (for the lack of better word) strings for those to work
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.