Problem with sha.new

Rob Williscroft rtw at freenet.co.uk
Sat Jul 9 08:34:51 EDT 2005


Florian Lindner wrote in news:daodmf$4gf$00$1 at news.t-online.com in 
comp.lang.python:

> Hello,
> I try to compute SHA hashes for different files:
> 
> 
> for root, dirs, files in os.walk(sys.argv[1]):
>     for file in files:
>         path =  os.path.join(root, file)
>         print path
>         f = open(path)

Here you rebind 'sha' from what it was before (presumably the module sha)
to the result of 'sha.new' presumably the new 'sha' doesn't have a 'new'
method. try renameing your result variable.

>         sha = sha.new(f.read())
>         sha.update(f.read())
>         print sha.hexdigest()

    	result = sha.new(f.read())
    	result.update(f.read())
    	print result.hexdigest()

also I don't think you need the second call to update as f will
have been read by this time and it will add nothing.

> 
> 
> this generates a traceback when sha.new() is called for the second 
> time:
> 

>     sha = sha.new(f.read())
> AttributeError: new
> 

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/



More information about the Python-list mailing list