[Tutor] Please comment my -first- script
Bernard Lebel
python at bernardlebel.com
Thu Aug 19 09:24:20 CEST 2004
Hi Kent,
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)
>
> Sweet!!
Indeed, this is sweet. A big thanks for that.
>
> - You should put the setdefault() call inside the try block for
ValueError,
> because if you get the exception then sName and sPad haven't been set
(they
> will have stale values in them probably):
> try:
> sName, sPad, sExt =
oFile.split( '.' )
> aNames.setdefault( sName, []
> ).append( sPad )
> except ValueError:
> pass
Well yes, I didn't have the choice to do that, because otherwise the script
fails.
>
> By the way do you understand what the setdefault call is doing? This is
one
> 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?
Thanks
Bernard
More information about the Tutor
mailing list