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

Roy Smith roy at panix.com
Sun Sep 28 09:25:56 EDT 2008


In article <00ef327d$0$20666$c3e8da3 at news.astraweb.com>,
 Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:

> from random import randint
> ''.join(chr(randint(0, 255)) for i in xrange(len(input)))
> 
> 
> of course. How else should you get random bytes? :)

That a UUOL (Useless Usage Of Len; by analogy to UUOC).  This works just as 
well:

''.join(chr(randint(0, 255)) for i in input)



More information about the Python-list mailing list