[Tutor] [spoiler] Re: Shifting arrays as though they are a 'word'

Chip Wachob wachobc at gmail.com
Tue Oct 9 12:30:20 EDT 2018


Alan,

Yes, 2.7 here.  I wanted to use 3, but the API only supports 2.7.
And, I'm not about to get into rewriting an API. :)

So, octets it is.  Thank you for the clarification.

Yes, my background is C, let me look into your suggested method.

It is the shifting across those byte boundaries that is really messing
me up.  If only they were all just bytes..  but then that wouldn't be
any 'fun' would it?

Thank you,


On 10/9/18, Alan Gauld via Tutor <tutor at python.org> wrote:
> On 09/10/18 13:45, Chip Wachob wrote:
>
>> Another related question.  How do I know I want to do dir(int) vs.. I
>> don't know dir(long)?
>
> Because you want to convert the byte array into an int.
> And there is no long in Python...
>
>> And, when I do dir(int) I get the following results.  I must not be
>> seeing the from_bytes in this list...
>>
>>>>> dir(int)
>> ['__abs__', '__add__', '__and__', '__class__', '__cmp__',
>
> Ah, I assume this means you are using Python v2.7?
> I assumed you were using v3. The bytes operations were,
> I think, added in v3.
>
> That complicates things, I think you are probably best
> converting your byte list into a string and then using
> the struct module to convert your bytearray into an int.
> (struct is a bit like C's sscanf function if
> that helps - I seem to recall you know C?)
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list