Re: [Tutor] os.urandom()

2010-08-10 Thread Dave Angel
Steven D'Aprano wrote: On Tue, 10 Aug 2010 02:24:00 pm Dave Angel wrote: Any suggestions how to fix the Windows console to interpret utf8? I don't know about Windows, but under Linux there is a menu command for most xterms that let you set it. Googling led me to this page: which, if

Re: [Tutor] os.urandom()

2010-08-10 Thread Steven D'Aprano
On Wed, 11 Aug 2010 12:33:11 am Steven D'Aprano wrote: > > Any suggestions how to fix the Windows console to interpret utf8? > > I don't know about Windows, but under Linux there is a menu command > for most xterms that let you set it. > > Googling led me to this page: Oops, forgot to paste the l

Re: [Tutor] os.urandom()

2010-08-10 Thread Tim Golden
On 10/08/2010 15:33, Steven D'Aprano wrote: On Tue, 10 Aug 2010 02:24:00 pm Dave Angel wrote: [...] Any suggestions how to fix the Windows console to interpret utf8? There are several tracker issues relating to this one. The current position seems to be: it's not easy. I've done no more than

Re: [Tutor] os.urandom()

2010-08-10 Thread Steven D'Aprano
On Tue, 10 Aug 2010 02:24:00 pm Dave Angel wrote: > > repr() returns the string > > representation, not the byte representation. Try this: > > That's what I was missing. Somehow I assumed it was converting to > byte strings. > > I had assumed that it reverted to /u or /U whenever a >

Re: [Tutor] os.urandom()

2010-08-09 Thread Dave Angel
Steven D'Aprano wrote: On Mon, 9 Aug 2010 11:51:34 pm you wrote: (Context: Python 3.x, where strings are unicode.) repr() returns the string representation, not the byte representation. Try this: That's what I was missing. Somehow I assumed it was converting to byte strings. I

Re: [Tutor] os.urandom()

2010-08-09 Thread Steven D'Aprano
On Mon, 9 Aug 2010 11:51:34 pm you wrote: > Steven D'Aprano wrote: > > On Mon, 9 Aug 2010 07:23:56 pm Dave Angel wrote: > >> Big difference between 2.x and 3.x. In 3.x, strings are Unicode, > >> and may be stored either in 16bit or 32bit form (Windows usually > >> compiled using the former, and Li

Re: [Tutor] os.urandom()

2010-08-09 Thread Dave Angel
Steven D'Aprano wrote: On Mon, 9 Aug 2010 07:23:56 pm Dave Angel wrote: Big difference between 2.x and 3.x. In 3.x, strings are Unicode, and may be stored either in 16bit or 32bit form (Windows usually compiled using the former, and Linux the latter). That's an internal storage that

Re: [Tutor] os.urandom()

2010-08-09 Thread Steven D'Aprano
On Mon, 9 Aug 2010 07:23:56 pm Dave Angel wrote: > Big difference between 2.x and 3.x. In 3.x, strings are Unicode, and > may be stored either in 16bit or 32bit form (Windows usually compiled > using the former, and Linux the latter). That's an internal storage that you (generic you) the Python

Re: [Tutor] os.urandom()

2010-08-09 Thread Dave Angel
Richard D. Moores wrote: On Sun, Aug 8, 2010 at 08:11, bob gailer wrote: On 8/8/2010 1:57 AM, Richard D. Moores wrote: 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

Re: [Tutor] os.urandom()

2010-08-08 Thread Richard D. Moores
On Sun, Aug 8, 2010 at 08:11, bob gailer wrote: > On 8/8/2010 1:57 AM, Richard D. Moores wrote: >> 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 But >>> os.urandom(6) b'\x13\xf1\x

Re: [Tutor] os.urandom()

2010-08-08 Thread bob gailer
On 8/8/2010 1:57 AM, Richard D. Moores wrote: On Sat, Aug 7, 2010 at 17:00, Alan Gauld wrote: "Richard D. Moores" 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)

Re: [Tutor] os.urandom()

2010-08-08 Thread Richard D. Moores
On Sun, Aug 8, 2010 at 01:05, Alan Gauld wrote: > > "Richard D. Moores" wrote > >> 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? > > Yes except that its not urandomthat is printing those values.

Re: [Tutor] os.urandom()

2010-08-08 Thread Steven D'Aprano
On Sun, 8 Aug 2010 03:57:39 pm Richard D. Moores wrote: > So if os.urandom() had been written so that it printed only hex, > b'l\xbb\xae\xb7\x0ft' would have been os.urandom() doesn't *print* anything. It RETURNS a byte string. What you do with it is your business. In your case, you fail to sav

Re: [Tutor] os.urandom()

2010-08-08 Thread Alan Gauld
"Richard D. Moores" wrote 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? Yes except that its not urandomthat is printing those values. urandom returns a string of bytes. Its the Python interpreter c

Re: [Tutor] os.urandom()

2010-08-07 Thread Richard D. Moores
On Sat, Aug 7, 2010 at 17:00, Alan Gauld wrote: > > "Richard D. Moores" 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 val

Re: [Tutor] os.urandom()

2010-08-07 Thread Steven D'Aprano
On Sun, 8 Aug 2010 09:32:02 am Richard D. Moores wrote: > On Sat, Aug 7, 2010 at 15:26, Alan Gauld wrote: > > Python is telling you its bytes with the b at the front. > > The \x tells you they are hex values. > > > > (*)The fact its 5 is odd since you seem to pass 6 as an argument! > > When I try

Re: [Tutor] os.urandom()

2010-08-07 Thread Alan Gauld
"Richard D. Moores" wrote (*)The fact its 5 is odd since you seem to pass 6 as an argument! When I try it I get 6 bytes back. For some reason I never spotted the L at the end of the string last time. So it was 6 bytes. I suspect the L was read (by me) as the L at the end of a Long integer

Re: [Tutor] os.urandom()

2010-08-07 Thread Alan Gauld
"Richard D. Moores" 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 os.urandom(6) b'\x1f\x00~\xfbz\x98' Sa

Re: [Tutor] os.urandom()

2010-08-07 Thread Richard D. Moores
On Sat, Aug 7, 2010 at 16:34, bob gailer 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 "", line 1, in File "C:\Python31\lib\encodings

Re: [Tutor] os.urandom()

2010-08-07 Thread Richard D. Moores
On Sat, Aug 7, 2010 at 15:01, Dominik Danter wrote: > You could try something like binascii.hexlify(os.urandom(6)) to create hex. >>> os.urandom(6) b'f\xc8rnr\xea' >>> binascii.hexlify(b'f\xc8rnr\xea') b'66c8726e72ea' >>> os.urandom(6) b'D\xe9?\xda\xd80' >>> binascii.hexlify(b'D\xe9?\xda\xd80')

Re: [Tutor] os.urandom()

2010-08-07 Thread bob gailer
On 8/7/2010 6:29 PM, Evert Rol wrote: [a for a in map(chr, os.urandom(6))] Overkill! map(chr, os.urandom(6)) is sufficient. Or [chr(x) for x in os.urandom(6))] The latter is easier to read. -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tuto

Re: [Tutor] os.urandom()

2010-08-07 Thread Richard D. Moores
On Sat, Aug 7, 2010 at 15:26, Alan Gauld wrote: > Python is telling you its bytes with the b at the front. > The \x tells you they are hex values. > > (*)The fact its 5 is odd since you seem to pass 6 as an argument! > When I try it I get 6 bytes back. Yes, the number of bytes seems to <= 6, or

Re: [Tutor] os.urandom()

2010-08-07 Thread Evert Rol
> > > using Vista, Python 3.1: > import os os.urandom(6) > b'\xd1\xfc\xb0\x14\xeaL' > > So what is this output? What in ascii? What in hex? Do those > questions even make sense? It returns just what it says in

Re: [Tutor] os.urandom()

2010-08-07 Thread Alan Gauld
"Richard D. Moores" wrote import os os.urandom(6) b'\xd1\xfc\xb0\x14\xeaL' So what is this output? What in ascii? What in hex? Do those questions even make sense? The documentation tells you: os.urandom(n)ΒΆ Return a string of n random bytes suitable for cryptographic use. So its a strin

[Tutor] os.urandom()

2010-08-07 Thread Richard D. Moores
using Vista, Python 3.1: >>> import os >>> os.urandom(6) b'\xd1\xfc\xb0\x14\xeaL' So what is this output? What in ascii? What in hex? Do those questions even make sense? I've tried 2 things to get at it: >>> import bina