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

(yzsuai) #1

of Python Internet scripting and as a realistically scaled example that ties together other
tools we’ve already seen, such as threads and tkinter GUIs.


Like the pymail console-based program we wrote in Chapter 13, PyMailGUI runs en-
tirely on your local computer. Your email is fetched from and sent to remote mail servers
over sockets, but the program and its user interface run locally. As a result, PyMailGUI
is called an email client: like pymail, it employs Python’s client-side tools to talk to mail
servers from the local machine. Unlike pymail, though, PyMailGUI is a full-featured
user interface: email operations are performed with point-and-click operations and
advanced mail processing such as attachments, save files, and Internationalization is
supported.


Like many examples presented in this text, PyMailGUI is a practical, useful program.
In fact, I run it on all kinds of machines to check my email while traveling around the
world teaching Python classes. Although PyMailGUI won’t put Microsoft Outlook out
of business anytime soon, it has two key pragmatic features alluded to earlier that have
nothing to do with email itself—portability and scriptability, which are attractive fea-
tures in their own right and merit a few additional words here:


It’s portable
PyMailGUI runs on any machine with sockets and a Python with tkinter installed.
Because email is transferred with the Python libraries, any Internet connection that
supports Post Office Protocol (POP) and Simple Mail Transfer Protocol (SMTP)
access will do. Moreover, because the user interface is coded with tkinter, PyMail-
GUI should work, unchanged, on Windows, the X Window System (Unix, Linux),
and the Macintosh (classic and OS X), as long as Python 3.X runs there too.
Microsoft Outlook may be a more feature-rich package, but it has to be run on
Windows, and more specifically, on a single Windows machine. Because it gener-
ally deletes email from a server as it is downloaded by default and stores it on the
client, you cannot run Outlook on multiple machines without spreading your email
across all those machines. By contrast, PyMailGUI saves and deletes email only on
request, and so it is a bit friendlier to people who check their email in an ad hoc
fashion on arbitrary computers (like me).


It’s scriptable
PyMailGUI can become anything you want it to be because it is fully programma-
ble. In fact, this is the real killer feature of PyMailGUI and of open source software
like Python in general—because you have full access to PyMailGUI’s source code,
you are in complete control of where it evolves from here. You have nowhere near
as much control over commercial, closed products like Outlook; you generally get
whatever a large company decided you need, along with whatever bugs that com-
pany might have introduced.
As a Python script, PyMailGUI is a much more flexible tool. For instance, we can
change its layout, disable features, and add completely new functionality quickly
by changing its Python source code. Don’t like the mail-list display? Change a few


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