[Tutor] os.urandom()

bob gailer bgailer at gmail.com
Sun Aug 8 17:11:33 CEST 2010


On 8/8/2010 1:57 AM, Richard D. Moores wrote:
> On Sat, Aug 7, 2010 at 17:00, Alan Gauld<alan.gauld at btinternet.com>  wrote:
>    
>> "Richard D. Moores"<rdmoores at gmail.com>  wrote
>>
>>      
>>> Yes, the number of bytes seems to<= 6, or is it?:
>>>        
>>>>>> os.urandom(6)
>>>>>>              
>>> b'\xf1\x1c\x15\x83\x14\x0e'
>>>        
>> ok
>>
>>      
>>>>>> os.urandom(6)
>>>>>>              
>>> b'l\xbb\xae\xb7\x0ft'
>>>        
>> still ok - the l and t at the ends are valid characters so Python
>> prints the letter
>>      
>    
>>>> hex(ord('t'))
>>>>          
> '0x74'
>    
>>>> hex(ord('l'))
>>>>          
> '0x6c'
>
> So if os.urandom() had been written so that it printed only hex,
> b'l\xbb\xae\xb7\x0ft' would have been
>
> b'\x6c\xbb\xae\xb7\x0f\x74' , right?
>
> Thanks very much for that, Alan.
>
> How were we supposed to know that all the hexes have 2 digits?

In version 2.6.5 Language Reference 2.4.1 - String literals:
\xhh Character with hex value hh

-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list