str() should convert ANY object to a string without EXCEPTIONS !

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Sep 28 03:56:49 EDT 2008


On Sun, 28 Sep 2008 19:03:42 +1300, Lawrence D'Oliveiro wrote:

> In message
> <9890864a-09f9-40d6-b2cc-5028e7a0c8c3 at q26g2000prq.googlegroups.com>, est
> wrote:
> 
>> The problem is, why the f**k set ASCII encoding to range(128) ????????
> 
> Because that's how ASCII is defined.
> 
>> while str() is internally byte array it should be handled in range(256)
>> !!!!!!!!!!
> 
> But that's for random bytes. How would you convert an arbitrary object
> to random bytes?

from random import randint
''.join(chr(randint(0, 255)) for i in xrange(len(input)))

of course. How else should you get random bytes? :)



-- 
Steven



More information about the Python-list mailing list