Forwarding to tutor. Again, apologies that I didn't respond earlier. Overloaded.
---------- Forwarded message ---------- From: Андрей Пугачев <pugachov.and...@gmail.com> Date: Tue, Feb 17, 2015 at 11:58 AM Subject: Re: [Tutor] Need help with find error To: Danny Yoo <d...@hashcollision.org> Anybody can help with this? 2015-02-07 10:27 GMT+02:00 Андрей Пугачев <pugachov.and...@gmail.com>: > > Sorry for my absense, but you want to say, that loop in code isn't working? > (in main()-function) > When category is empty code must print 2 last rows, but I have error.... > > I learn python book M. Dawson and this exercise from his book. > I add original working files, where points count as score +=1 and all works. > But if I add some points to each question code don't work. > I can't understand it/ > > > > 2015-02-04 20:24 GMT+02:00 Danny Yoo <d...@hashcollision.org>: >> >> As a revision of my initial question, when we look at next_block(), >> it's documented as follows: >> >> ############################################ >> def next_block(the_file): >> """Return the next block of data from the trivia file.""" >> .... >> ############################################ >> >> What if there are no more blocks in the file? What should happen then? >> >> Let's say that we do a test, where we pass in the empty file to next_block(). >> >> ###################### >> from io import StringIO >> x = next_block(StringIO('')) >> ###################### >> >> What do you want to happen in this situation? >> >> --- >> >> As a side note: if you have control over the data format, you might >> want to consider using JSON rather than a line-based format. If you >> use JSON, this takes care of a few issues that you are working around >> now. >> >> For example, you can reuse the newline escapes rather than define your >> own convention. Also, rather than read a stream of records, where you >> have to deal with the end of the file, you might just read one JSON >> object that represents your whole trivia file, which will simplify >> your program's logic. >> >> See: https://docs.python.org/2/library/json.html and use your favorite >> web search engine for 'json python tutorial', and you should be able >> to find some useful information. If you have questions, please feel >> free to ask. > > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor