[Tutor] dictionary looping problem

Steve Willoughby steve at alchemy.com
Tue Dec 2 22:25:34 CET 2008

On Tue, Dec 02, 2008 at 01:08:09PM -0800, Jeremiah Jester wrote:
> Hello,
> I'm trying to gather a list of files and md5 hash them to do a checksum.
> I've created a function for each dictionary. However, when i print out
> the dictionary I don't get all the items. Any ideas?

Yep.  Don't use os.system() there.  

1. you're running the "md5" program externally when you don't need to,
   since Python has the ability to compute md5 checksums on its own,
   which you already know because you imported that module at the top
   of your script (and then didn't use).

2. The return value from os.system() is NOT the hash, so what you're
   storing in the dictionary is not going to be that unique, and so
   each call which yields the same return value (0, usually) will 
   overwrite that element in the dict.

Steve Willoughby    |  Using billion-dollar satellites
steve at alchemy.com   |  to hunt for Tupperware.

More information about the Tutor mailing list