Re: Question regarding checksuming of a file

2006-05-14 Thread Heiko Wundram
Am Sonntag 14 Mai 2006 22:29 schrieb Paul Rubin: > Andrew Robert <[EMAIL PROTECTED]> writes: > > When I run the script, I get an error that the file object does not have > > the attribute getblocks. > > Woops, yes, you have to call getblocks(f). Also, Heiko says you can't > use "return" to break

Re: Question regarding checksuming of a file

2006-05-14 Thread Paul Rubin
Andrew Robert <[EMAIL PROTECTED]> writes: > When I run the script, I get an error that the file object does not have > the attribute getblocks. Woops, yes, you have to call getblocks(f). Also, Heiko says you can't use "return" to break out of the generator; I thought you could but maybe I got co

Re: Question regarding checksuming of a file

2006-05-14 Thread Heiko Wundram
Am Sonntag 14 Mai 2006 20:51 schrieb Andrew Robert: > def getblocks(f, blocksize=1024): > while True: > s = f.read(blocksize) > if not s: return > yield s This won't work. The following will: def getblocks(f,blocksize=1024): while True:

Re: Question regarding checksuming of a file

2006-05-14 Thread Andrew Robert
When I run the script, I get an error that the file object does not have the attribute getblocks. Did you mean this instead? def getblocks(f, blocksize=1024): while True: s = f.read(blocksize) if not s: return yield s def getsum(self):

Re: Question regarding checksuming of a file

2006-05-14 Thread Paul Rubin
"Ant" <[EMAIL PROTECTED]> writes: > def getSum(self): > md5Sum = md5.new() > f = open(self.filename, 'rb') > for line in f: > md5Sum.update(line) > f.close() > return md5Sum.hexdigest() This should work, but there is one hazard if the file is ver

Re: Question regarding checksuming of a file

2006-05-14 Thread Ant
A script I use for comparing files by MD5 sum uses the following function, which you may find helps: def getSum(self): md5Sum = md5.new() f = open(self.filename, 'rb') for line in f: md5Sum.update(line) f.close() return md5Sum

Re: Question regarding checksuming of a file

2006-05-13 Thread Andrew Robert
Roy Smith wrote: >> >> However this does not appear to be actually returning the checksum. >> >> Does anyone have insight into where I am going wrong? > > After calling update(), you need to call digest(). Update() only updates > the internal state of the md5 state machine; digest() returns the

Re: Question regarding checksuming of a file

2006-05-13 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Andrew Robert <[EMAIL PROTECTED]> wrote: > Good evening, > > I need to generate checksums of a file, store the value in a variable, > and pass it along for later comparison. > > The MD5 module would seem to do the trick but I'm sketchy on implementation. > > >

Re: Question regarding checksuming of a file

2006-05-13 Thread Andrew Robert
Actually, I think I got it but would like to confirm this looks right. import md5 checksum = md5.new() mfn = open(self.file_name, 'r') for line in mfn.readlines(): checksum.update(line) mfn.close() cs = checksum.hexdigest() print

Re: Question regarding checksuming of a file

2006-05-13 Thread Edward Elliott
Andrew Robert wrote: > m=md5.new() > contents = open(self.file_name,"rb").read() > check=md5.update(contents) > > However this does not appear to be actually returning the checksum. the docs are your friend, use them. hint: first you eat, then you... http://docs.python.org/lib/module-md5.html

Question regarding checksuming of a file

2006-05-13 Thread Andrew Robert
Good evening, I need to generate checksums of a file, store the value in a variable, and pass it along for later comparison. The MD5 module would seem to do the trick but I'm sketchy on implementation. The nearest I can see would be import md5 m=md5.new() contents = open(self.file_name,"rb").