Names are nothing more then a distinguishing mark to define something that hasn't already been defined.. Humans are great because they wrap huge functional and contextual definitions to names and dont even realise it.. Think of your own name.. if that is all I used to describe you I'd never understand what was different between you and anyone else with your name.. but when I think of "you"( aka you in context), I can list tons of stuff that makes you who you are.. Try and imagine your name if I took it completely out of context and functionality... You'd have some name more like "Brian, slacker of the eastside, teller of the great jokes, driver of the SUV, son of Marry and George, birth-father of little billy, owner of many pc's"... vs the guy that lives in another neighborhood who'd have to be named "Brian, civil servant of the eastside, impressor of women, driver of the sports car, Adopted,birth father to many across the town, owner of no pc's" if you wanted to describe someone.
Rambling aside... I was just trying to take a light hearted spin because the poor mechanic we have subjected for abuse in this debate struck me funny.
On 10/17/06,
Luke Paireepinart <[EMAIL PROTECTED]> wrote:
Kent Johnson wrote:
> Chris Hengge wrote:
>
>> I chose the way I used the names because to me...
>>
>> outFile = open(aFile.lower(), 'w') # Open output buffer for writing.
>> = open a file with lowercase name for writing.
>> it is implied that aFile is from the zip, since it is created in the
>> loop to read the zip..
>>
>> outFile.write(zFile.read(insideZip)) # Write the file.
>> = write what is read from inside the zip file.
>>
>
> This sub-thread seems to have turned into "let's beat on Chris for the
> way he names things" which certainly isn't what I intended. Ultimately
> it is up to the program author to use the names that he thinks
> communicate most clearly.
>
Well, yes, and it's up to the auto mechanic to use the parts he thinks
are best when he fixes your car.
However, one hopes that he has training in how to determine which parts
are the most durable, safest, etc, etc.
Similarly, while it's up to you to choose variable names, we still hope
that you know why you're choosing certain names.
> But I think the actual naming was secondary to the my main point which
> is that the value for 'insideZip' is read from the zip, if you assign to
> that name and keep it in that name the code is easier to follow because
> the value that doesn't change stays in a name that doesn't change.
>
> So using your names, it would read
> for insideZip in zFile.namelist():
> for ext in ['.cap', '.hex', '.fru', '.cfg', '.sdr']:
> if insideZip .lower().endswith(ext):
> if "/" in insideZip :
> aFile = aFile.rsplit('/', 1)[-1]
> elif "\\" in insideZip :
> aFile = aFile.rsplit('\\', 1)[-1]
> else:
> aFile = insideZip
>
> This way inzideZip is always the name from inside the zip, and aFile is
> always the name of the file to write.
>
I think it'd be most clear if you did something like:
ext = ['.cap','.hex','.fru','.cfg','.sdr']
for zipFile in zFile.namelist():
if os.path.splitext(zipFile)[-1] in ext:
outFile = os.path.split(zipFile)[-1]
but that's just me :)
I've gone back and read your code.
The problem Kent was pointing out was that your for loop was iterating
over a variable called aFile,
and you were changing this variable during the loop. This is generally
considered Bad Practice.
That's all he meant.
I think.
HTH,
-Luke
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor