Re: [Tutor] Generator expressions...

2011-02-27 Thread Modulok
>> import hashlib >> >> fd = open('/dev/urandom', 'rb') >> gen = (hashlib.sha256(i).hexdigest() for i in fd.read(4096)) >> >> try: >>for i in gen: >>print i #<-- This loop should never end... but does. Why? >> >> except KeyboardInterrupt: >>gen.close() >>fd.close() >>pri

Re: [Tutor] Generator expressions...

2011-02-27 Thread Corey Richardson
On 02/27/2011 04:34 PM, Modulok wrote: > > import hashlib > > fd = open('/dev/urandom', 'rb') > gen = (hashlib.sha256(i).hexdigest() for i in fd.read(4096)) > I think the problem is that you're only reading 4096 bits (bytes? No idea), and iterating through that. I could be wrong. -- Corey Ric

Re: [Tutor] Generator expressions...

2011-02-27 Thread Hugo Arts
On Sun, Feb 27, 2011 at 10:34 PM, Modulok wrote: > > import hashlib > > fd = open('/dev/urandom', 'rb') > gen = (hashlib.sha256(i).hexdigest() for i in fd.read(4096)) > > try: >    for i in gen: >        print i     #<-- This loop should never end... but does. Why? > > except KeyboardInterrupt: >

[Tutor] Generator expressions...

2011-02-27 Thread Modulok
List, I was messing around with generator expressions. I tried to make a script that would read a few bytes from '/dev/urandom' for eternity. It then did something pointless like computing checksums and printing them out. Unfortunately, the script only runs a few seconds and then terminates. I'm n