[Tutor] Should I use generators here?

Tony C cappy2112 at gmail.com
Mon May 8 20:08:38 CEST 2006


Thus you should probably do:
>
>        try:
>            fh=open(Onefile, "r")
>            Filecontents = fh.readlines()  # these files are very
> small,
>
>            # other code here
>            Summary[Onefile] = deepcopy(Stats)    # associate each
>
>            fh.close()
>        except IOError:
>            print("\nFATAL ERROR ocurred opening %s for input" %
> Onefile)
>        except IOError:
>                print("\nFatal error occurred reading from %s\n\n" %
> InputFilename)
>
>
> >>Even if you decide to stick with two try blocks you shouldn't need the
> >>else construct. Either break or exit as part of the first except
> >>handler.


Got it.




>
> >>I'm also somewhat confused as to why you seem so interested
> >> the length of the longest filename?



Apologies fo rnot elaborating fully.
The program is about 98% finished. It collects the stats just fine, and
displays them.
Howevr, I wanted to display the stats for each file, as well as an overall
summary of all files.
Knowing the length of the longest filename is only to be used for formatting
the output on the screen, so all the stats below it will
line up in the same column.

example...
(this is how the stats for each file is displayed now)

File1.bas   100 Lines, 200 subs, 300 funcs
RealllyBigFilename.bas 2000 lines, 2000 subs, 4000 funcs

This is what I what it will look like when the display formatting is
finished
File1.bas                       100 Lines,  200 subs,   300 funcs
RealllyBigFilename.bas 2000 lines, 2000 subs, 4000 funcs

No need to deal with this issue, I can figure that out.
I'm more interested in performance tweaks.
Thanks for your reply

Tony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060508/f9c3e7ce/attachment.html 


More information about the Tutor mailing list