[Tutor] Trivia

Vincent Balmori vincentbalmori at yahoo.com
Fri Jun 24 09:58:30 CEST 2011


"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.



More information about the Tutor mailing list