[Tutor] Zipfile and File manipulation questions.

Chris Hengge pyro9219 at gmail.com
Tue Oct 17 19:23:51 CEST 2006

I get what you are trying to say.. but I'm looking at the code after
changing names, and I think it makes more sense in the code my way because
of the following lines..

outFile = open(aFile.lower(), 'w')
#open 'afile' named with lowercase to 'w'rite
#write what you read 'insidezip'

This is what I mean by functional names verses descriptive... Your way I'd
have a better grasp of the data, my way I feel I have a better grasp of what
is going on in my code. When I'm done writing my code and go back through
the documentation I'll be adding all the variables used to the docstring,
inputs, outputs.. all that jazz. Even if I didn't, and I'd never seen this
code before, I'd try to figure out what it is doing before caring what data
is being manipulated. Think about it... understanding the purpose in context
will give me a better understanding of what the data going in, and coming
out should appear to be, then hoping the author picked the right stuff.
Perhaps I've adopted this habbit after years of trying to learn from
snippets of code online where people use completely generic variable names
as references, and kind of started ignoring variable names..

Seriously... its just how you look at things... I obviously read code and
get my understanding very differently then many people on here. I take more
of a top down approach, while it sounds many of you take a bottom up

On 10/17/06, Kent Johnson <kent37 at tds.net> 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.
> 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 guess for declaration it isn't very clear, but thats what comments are
> > for?
> The comments about comments have been on the mark, I think. A helpful
> guideline I use is, when I think I need a comment, look at the names I
> am using and see if I can create a function whose name conveys what I
> wanted to say in the comment.
> Kent
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061017/c06f9229/attachment.htm 

More information about the Tutor mailing list