>> 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()
>>    print "\nBye!"
>>

> Check out the generator expression. What are you iterating over? How
> long is the string returned by the read?

I knew it was subtle. I was trying to use 'read(4096)' like open()'s
buffersize parameter. (Which it's obviously isn't.)

Thanks!
-Modulok-
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to