Pyhon 2.x or 3.x, which is faster?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Mar 7 23:40:19 EST 2016


On Tuesday 08 March 2016 12:41, BartC wrote:

> On 08/03/2016 01:19, Steven D'Aprano wrote:
>> On Tue, 8 Mar 2016 07:19 am, BartC wrote:
>>
>>> I don't have to hand a jpeg file that it can't
>>> decode.
>>
>> Run this under Python 2:
>>
>> from random import randint
>> blob = [randint(0, 256) for i in range(16*1024)]
>>
>> with open('broken.jpg', 'wb') as f:
>>      f.write(''.join(blob))
>>
>> If your software can decode that, it will be a miracle.
>>
> 
> That's not a jpeg file.

Nevertheless, in the real world, you have to deal with corrupt JPGs and 
files mislabelled as JPGs. And "crashing" doesn't count as "deal with" :-)


> (You code didn't run even on Python 2


Serves me right for not testing it before posting :-(

Change the second line to:

blob = [chr(randint(0, 255)) for i in range(16*1024)]

and it works for me.




-- 
Steve




More information about the Python-list mailing list