Occasionally I go through my bookshelves and get rid of books not likely to be read or re-read. Probably five years ago, I purged some of my shelves at work. I don't remember most of what went, but this week I found myself wishing I had a book I had been confident I wouldn't open again, Python Programming on Win32
This week I was putting together a makeshift script to take a few records from the beginning of file, a few from its end, and display them in an Excel worksheet. The central logic is simple and took little time to finish. However, it required a bit more than that.
It was desirable to let the user select the file with a graphical interface, for one thing. After some time peering at the Help section and Googling for hints, I figured out how to display a win32ui.FileDialog. That done, the script seemed to work pretty well. It worked correctly when I selected the correct file, when the file was accessible, and so on. That will not always be the case, so there needed to be some way to print a message and exit gracefully.
Without a console, the "print" statement is useless. Various promising objects I tried to create from the win32ui package blew up with unhelpful error messages. I fell back on Tkinter, which looked promising also. But I couldn't make Tkinter exit gracefully, and I have no idea why that is so. Eventually I discovered win32gui.TextBox, which did just what I need. I imagine that somebody proficient in the old Microsoft Foundation Classes would not have needed this explained.
I might have lost four hours on items that perhaps I could have looked up in the book I discarded those years ago. It takes up no more room than another book I still have and haven't opened since the last time I needed to look at the behavior of an SMTP agent (three years ago? four?). But I will continue to get rid of books and take my chances. Now I just need to remember why I still have Practical Programming in Tcl and Tk, which I hadn't opened in years, and takes up the shelf space of a large-print Bible.
No comments:
Post a Comment