What do the ">>" symbols mean in Python code: map(chr,[x,x>>8,y])

176 Views Asked by At

The error code I get in another file that uses it is:

Traceback (most recent call last):
  File "C:\Anaconda\lib\site-packages\pyahoolib-0.2-py2.7.egg\yahoo\session.py", line 107, in listener
    t.send_pk(consts.SERVICE_AUTHRESP, auth.hash(t.login_id, t.passwd, p[94]))
  File "C:\Anaconda\lib\site-packages\pyahoolib-0.2-py2.7.egg\yahoo\auth.py", line 73, in hash
    hs = md5.new(mkeystr+"".join(map(chr,[x,x>>8,y]))).digest()
ValueError: chr() arg not in range(256)

UPDATE: @merlin2011: This is confusing me. the code is hs = md5.new(mkeystr+"".join(map(chr,[x,x>>8,y]))).digest()

Where the chr has a comma after it. I thought it was a function from doc.python.org: chr(i)

Return a string of one character whose ASCII code is the integer i. For example, chr(97) returns the string 'a'. This is the inverse of ord(). The argument must be in the range [0..255], inclusive; ValueError will be raised if i is outside that range. See also unichr(). 

If so, is [x,x>>8,y] an iterable for map() I just don't recognize yet?

Also, I don't want to change any of this code because it is part of the pyahoolib-0.2 auth.py file. But to get it all working I do not know what to do.

2

There are 2 best solutions below

0
Christian Tapia On

It's the Binary Right Shift Operator:

From Python Wiki:

x >> y: Returns x with the bits shifted to the right by y places. This is the same as integer-dividing (\\) x by 2**y.

2
merlin2011 On

In case you were wondering, the error message means that chr only accepts arguments inside the range 0 to 256, and your map function is causing it to be called with a value that is outside that range.