Re: s = sha1(random()).hexdigest()

2009-01-16 Thread Paul Rubin
gert writes: > Is this the new way to create a list in Python3.0 ? > s=('test',) That is a 1-tuple in both 2.x and 3.0. For a list, you'd say s = ['test'] -- http://mail.python.org/mailman/listinfo/python-list

Re: s = sha1(random()).hexdigest()

2009-01-16 Thread gert
On Jan 17, 1:14 am, gert wrote: > On Jan 16, 7:08 am, "Martin v. Löwis" wrote: > > > >  s = urandom(10).encode('hex') > > > >  AttributeError: 'bytes' object has no attribute 'encode' > > > py> binascii.hexlify(os.urandom(10)) > > b'92b91d5734a9fe562f23' > > sqlite3 > >  s = hexlify(urandom(10))

Re: s = sha1(random()).hexdigest()

2009-01-16 Thread gert
On Jan 16, 7:08 am, "Martin v. Löwis" wrote: > >  s = urandom(10).encode('hex') > > >  AttributeError: 'bytes' object has no attribute 'encode' > > py> binascii.hexlify(os.urandom(10)) > b'92b91d5734a9fe562f23' > sqlite3 s = hexlify(urandom(10)) db.execute('SELECT sid FROM sessions WHERE sid=?

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread Martin v. Löwis
> s = urandom(10).encode('hex') > > AttributeError: 'bytes' object has no attribute 'encode' py> binascii.hexlify(os.urandom(10)) b'92b91d5734a9fe562f23' Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread Paul Rubin
"James Mills" writes: > >>> "".join([hex(c) for c in os.urandom(10)]) > '0x540x6c0xdf0xd90xe10x7c0x330x370x9a0x8' That doesn't look so good, because of all the 0x. -- http://mail.python.org/mailman/listinfo/python-list

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread James Mills
On Fri, Jan 16, 2009 at 2:46 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > gert writes: >> s = urandom(10).encode('hex') >> AttributeError: 'bytes' object has no attribute 'encode' > > Oh, Python 3. It's done some different way, someone else will have to > specify. I'm still using 2

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread Paul Rubin
gert writes: > s = sha1(bytes(random(),'utf-8')).hexdigest() > i found this, looks let say strange. But it works :) Be careful, if you're relying on the uniqueness and unpredictability of this number for program security, that random() isn't designed for such purposes. Use os.urandom instead. --

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread Paul Rubin
gert writes: > s = urandom(10).encode('hex') > AttributeError: 'bytes' object has no attribute 'encode' Oh, Python 3. It's done some different way, someone else will have to specify. I'm still using 2.x. -- http://mail.python.org/mailman/listinfo/python-list

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread gert
On Jan 16, 1:20 am, Paul Rubin <http://phr...@nospam.invalid> wrote: > gert writes: > > s = sha1(random()).hexdigest() > > > TypeError: object supporting the buffer API required, > > > How does sha1 work in python3.0 please ? > > sha1 hashes strings, not num

Re: s = sha1(random()).hexdigest()

2009-01-15 Thread gert
On Jan 16, 1:14 am, gert wrote: > from random import random > from hashlib import sha1 > s = sha1(random()).hexdigest() > > TypeError: object supporting the buffer API required, > > How does sha1 work in python3.0 please ? s = sha1(bytes(random(),'utf-8')).hexdi

Re: [python3.0] s = sha1(random()).hexdigest()

2009-01-15 Thread Paul Rubin
gert writes: > s = sha1(random()).hexdigest() > > TypeError: object supporting the buffer API required, > > How does sha1 work in python3.0 please ? sha1 hashes strings, not numbers. Try using str(random()). But if you want some random hex digits, try os.urandom(10).encode(&#x

[python3.0] s = sha1(random()).hexdigest()

2009-01-15 Thread gert
from random import random from hashlib import sha1 s = sha1(random()).hexdigest() TypeError: object supporting the buffer API required, How does sha1 work in python3.0 please ? -- http://mail.python.org/mailman/listinfo/python-list