[Tutor] hash.update( argv[0] )
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Mon Apr 24 20:38:23 CEST 2006
> where outputVersion is a manual set variable in the program
> (so I have to purge all the imageFile each time I adjust the
> program. maybe this is going to work, less progressive approach
^^^^^^^^^^^
Hi George,
Just to make sure: by "progressive", I meant the technical concept:
progressive: read the file a chunk at a time rather than sucking the
file all at once.
*grin*
> # Use a hash of the parameters to generate a cache filename.
> hash = sha.new(texData)
> hash.update( "%d %d" % (density, int(texMag)) )
> hash.update( open(argv[0]).read() )
> name = hash.hexdigest()
> imageFile = "%s/%s.%s" % (imagePath, name, 'png')
>
> I cannot test till the evening because of $WORK; but is that a
> good way to do it?
Yes, I think this will work.
One thing that it may not be robust against is changes to the current
working directory. I'd recommend capturing the program's filename at the
program's entry as an absolute-pathed variable, so that if we shake things
up by changing current working directory, we should still be able to work.
The os.path module may be useful here:
http://www.python.org/doc/lib/module-os.path.html
It has a few path-normalizing functions that should make this a relatively
easy fix.
More information about the Tutor
mailing list