[Tutor] Intro
Alan Gauld
alan.gauld at btinternet.com
Tue Aug 30 02:30:30 CEST 2011
On 29/08/11 19:29, Cranky Frankie wrote:
> - reading the huge quote file (hundreds of entries, two strings,
> author and quotation) in each time the program starts
>
> - loading the quotes into an array in the program
If you just want a random quote find the size of the file.
Generate a random number in that range and go back to find
the start of the quote.(Assuming some readily identifiable
marker exists)
Or, if you write a quote maintenance program to add/delete
quotes then even easier is to keep a tally of the number
of quotes at the start of the file and then generate the
random number based on that. Then simply read forward
that many quotes.
If it was a really big file(millions of quotes) you could
store a table of contents including the quote number and
offset, but I suspect you haven't that many quotes yet...
> I'm satisfied to use a dialog box, I don't need a GUI at this point so
> no tkinter (yet).
Consider EasyGUI, its ideal for that.
Altthough you could use the standard Tkinter dialogs too
(from which easyGUI is built I suspect)
The Talking to the User topic of my tutor describes EasyGUI
and the GUI topic describes the basic Tkinter message dialogs.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list