[Tutor] os.urandom()
Richard D. Moores
rdmoores at gmail.com
Sun Aug 8 01:55:43 CEST 2010
On Sat, Aug 7, 2010 at 16:34, bob gailer <bgailer at gmail.com> wrote:
> [chr(x) for x in os.urandom(6))]
Correcting this to [chr(x) for x in os.urandom(6)],
most of the time I get an error:
>>> [chr(x) for x in os.urandom(6)]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python31\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\xb9' in
position 12: character maps to <undefined>
But once in a while it works:
>>> [chr(x) for x in os.urandom(6)]
['\x9d', '\x9b', '\x0e', 'ê', '^', 'N']
(remember, I'm using Windows)
Dick
More information about the Tutor
mailing list