[Tutor] Please comment my -first- script
python at bernardlebel.com
Thu Aug 19 09:24:20 CEST 2004
Thanks for these new suggestions, again I implemented them and all is well.
See my comments below.
----- Original Message -----
From: "Kent Johnson" <kent_johnson at skillsoft.com>
To: <python at bernardlebel.com>
Sent: Thursday, August 19, 2004 4:15 AM
Subject: Re: [Tutor] Please comment my -first- script
> Change line 141 to build a list of the integer pads instead of strings:
> aNames.setdefault( sName,  ).append(
> int(sPad) )
> Now your loop to check all the frames becomes just a few lines:
> for iFrame in range( iStart, iEnd + 1 ):
> if not iFrame in aPad:
> # So we reached here
> because we could never find a match for the virtual padding and the
> collected ones.
> print ' Not
> found: ' + sName + '.' + str(iFrame)
Indeed, this is sweet. A big thanks for that.
> - You should put the setdefault() call inside the try block for
> because if you get the exception then sName and sPad haven't been set
> will have stale values in them probably):
> sName, sPad, sExt =
oFile.split( '.' )
> aNames.setdefault( sName, 
> ).append( sPad )
> except ValueError:
Well yes, I didn't have the choice to do that, because otherwise the script
> By the way do you understand what the setdefault call is doing? This is
> of the coolest Python idioms I know. (I'll let you figure it out :-)
Hum not really. I have looked in the documentation but could not find much
details about that. Can you elaborate if you don't mind?
More information about the Tutor