[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

html2text.py
A rudimentary parser for extracting plain text from HTML-based emails


Finally, the following are the new major modules coded in this chapter which are spe-
cific to the PyMailGUI program. In total, PyMailGUI itself consists of the ten modules
in this and the preceding lists, along with a handful of less prominent source files we’ll
see in this chapter:


SharedNames.py
Program-wide globals used by multiple files


ViewWindows.py
The implementation of View, Write, Reply, and Forward message view windows


ListWindows.py
The implementation of mail-server and local-file message list windows


PyMailGuiHelp.py
User-oriented help text, opened by the main window’s bar button


PyMailGui.py
The main, top-level file of the program, run to launch the main window


Code size


As a realistically scaled system, PyMailGUI’s size is also instructive. All told, PyMailGUI
is composed of 18 new files: the 10 new Python modules in the two preceding lists,
plus an HTML help file, a small configuration file for PyEdit pop ups, a currently unused
package initialization file, and 5 short Python files in a subdirectory used for alternate
account configuration.


Together, it contains some 2,400 new lines of program source code in 16 Python files
(including comments and whitespace), plus roughly 1,700 lines of help text in one
Python and one HTML file (in two flavors). This 4,100 new line total doesn’t include
the four other book examples listed in the previous section that are reused in PyMail-
GUI. The reused examples themselves constitute 2,600 additional lines of Python pro-
gram code—roughly 1,000 lines each for PyEdit and mailtools alone. That brings the
grand total to 6,700 lines: 4,100 new + 2,600 reused. Of this total, 5,000 lines is in
program code files (2,400 of which are new here) and 1,700 lines is help text.*


I obtained these lines counts with PyEdit’s Info pop up, and opened the files with the
code button in the PyDemos entry for this program (the Source button in PyMailGUI’s



  • And remember: you would have to multiply these line counts by a factor of four or more to get the equivalent
    in a language like C or C++. If you’ve done much programming, you probably recognize that the fact that
    we can implement a fairly full-featured mail processing program in roughly 5,000 total lines of program code
    speaks volumes about the power of the Python language and its libraries. For comparison, the original 1.0
    version of this program from the second edition of this book was just 745 total lines in 3 new modules, but
    it also was very limited—it did not support PyMailGUI 2.X’s attachments, thread overlap, local mail files,
    and so on, and did not have the Internationalization support or other features of this edition’s PyMailGUI 3.X.


“Use the Source, Luke”| 1007
Free download pdf