[Tutor] Trivia

Christopher King g.nius.ck at gmail.com
Thu Jun 30 19:00:55 CEST 2011


Just some programming philosophy.

On Fri, Jun 24, 2011 at 3:58 AM, Vincent Balmori
<vincentbalmori at yahoo.com>wrote:

>
> "Your whole approach is very fragile in this respect, it only
> takes one small mistake in the data to wreck your program,.
> Somethjing like a config file format would be much more
> robust (and readable) the config reader module would make
> sure you got what you expected back. "
>
> Can you please explain more on what you mean by this?
>
>
> Alan Gauld wrote:
> >
> >
> > "Vincent Balmori" <vincentbalmori at yahoo.com> wrote
> >
> >> It's working fine now with the scoring, but now at the end of the
> >> program
> >> for some reason I get this error message:
> >>
> >
> "/Users/vincentbalmori/Desktop/Python/py3e_source/chapter07/trivia_challenge2.py",
> >> line 27, in next_block
> >>    point = int(next_line(the_file))
> >> ValueError: invalid literal for int() with base 10: ''
> >
> > Thats because after the last question you try to read another
> > block and don't check anywhere whether you actually read
> > anything. Your next_block code just assumes there will
> > always be valid data there, but at the end of the file there
> > won't be. You get away with category being blank
> > because replace() doesn't complain. But int() does.
> >
> > Your whole approach is very fragile in this respect, it only
> > takes one small mistake in the data to wreck your program,.
> > Somethjing like a config file format would be much more
> > robust (and readable) the config reader module would make
> > sure you got what you expected back.
> >
> > HTH,
> >
> >
> > --
> > Alan Gauld
> > Author of the Learn to Program web site
> > http://www.alan-g.me.uk/
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Trivia-tp31917610p31917979.html
> Sent from the Python - tutor mailing list archive at Nabble.com.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110630/d5e8d769/attachment.html>


More information about the Tutor mailing list