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

Alan Gauld alan.gauld at yahoo.co.uk
Tue Oct 9 12:10:24 EDT 2018


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




More information about the Tutor mailing list