Re: Problem with sha.new

2005-07-09 Thread Rob Williscroft
Florian Lindner wrote in news:[EMAIL PROTECTED] 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/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with sha.new

2005-07-09 Thread Dan Sommers
On Sat, 09 Jul 2005 13:49:12 +0200,
Florian Lindner <[EMAIL PROTECTED]> wrote:

> 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)
> sha = sha.new(f.read())
  ^^^

Now the name "sha" no longer refers to the sha module, but to the object
returned by sha.new.  Use a different name.

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

Regards,
Dan

-- 
Dan Sommers

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with sha.new

2005-07-09 Thread John Machin
Florian Lindner wrote:
> 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)
print "sha is", repr(sha) ### self-help !
> sha = sha.new(f.read())
print "sha is", repr(sha) ### self-help !
> sha.update(f.read())
> print sha.hexdigest()
> 
> 
> this generates a traceback when sha.new() is called for the second time:
> 
> /home/florian/testdir/testfile
> c95ad0ce54f903e1568facb2b120ca9210f6778f
> /home/florian/testdir/testfile2
> Traceback (most recent call last):
>   File "duplicatefinder.py", line 11, in ?
> sha = sha.new(f.read())
> AttributeError: new
> 
> What is wrong there?
> 
"sha" no longer refers to the module of that name; it refers to the 
sha-object returned by the FIRST call of sha.new. That sha-object 
doesn't have a method called "new", hence the AttributeError exception.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with sha.new

2005-07-09 Thread and-google
Florian Lindner wrote:

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

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

You have reassigned the variable 'sha'.

First time around, sha is the sha module object as obtained by 'import
sha'. Second time around, sha is the SHA hashing object you used the
first time around. This does not have a 'new' method.

Python does not have separate namespaces for packages and variables.
Modules are stored in variables just like any other object.

-- 
Andrew Clover
mailto:[EMAIL PROTECTED]
http://www.doxdesk.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with sha.new

2005-07-09 Thread Florian Lindner
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)
sha = sha.new(f.read())
sha.update(f.read())
print sha.hexdigest()


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

/home/florian/testdir/testfile
c95ad0ce54f903e1568facb2b120ca9210f6778f
/home/florian/testdir/testfile2
Traceback (most recent call last):
  File "duplicatefinder.py", line 11, in ?
sha = sha.new(f.read())
AttributeError: new

What is wrong there?

Thanks,

Florian
-- 
http://mail.python.org/mailman/listinfo/python-list