09.11.2016 Views

Foundations of Python Network Programming 978-1-4302-3004-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

■ INTRODUCTION<br />

Program Listings<br />

Indentation is always a problem when putting <strong>Python</strong> programs in a book, because when a program<br />

listing is broken between pages, it can be difficult to determine whether the indentation level happened<br />

to change at the page break. The editors at Apress were very supportive when I <strong>of</strong>fered an idea: we have<br />

inserted light gray chevrons to mark each four-space level <strong>of</strong> indentation.<br />

We used the » symbol because it is not a valid character in a <strong>Python</strong> program, and therefore—we<br />

hope—readers will not be confused and try to insert it in their actual listings! Everywhere that you see<br />

the gray double chevron, understand that the actual code listing simply contains a space, and that the<br />

chevrons are there to make the number <strong>of</strong> spaces easier for you to count. Please let us know whether you<br />

indeed find this innovation more or less confusing than a traditional, unadorned program listing.<br />

To learn a new programming concept, the best thing you can <strong>of</strong>ten do is to experiment. To<br />

encourage this, Apress makes the source code for their books' program listings freely available for<br />

download at apress.com. Please take advantage <strong>of</strong> this and transform the listings on these printed pages<br />

into living programs loaded into your text editor. You are even free to use the code in your own projects!<br />

In the source bundle, I am providing a special treat: even though this book targets <strong>Python</strong> 2, I have<br />

also provided a <strong>Python</strong> 3 version <strong>of</strong> every program listing for which the appropriate libraries are<br />

available. This means that you can take the techniques you learn in these pages and transfer them to the<br />

new version <strong>of</strong> the language by simply comparing the printed listing with the <strong>Python</strong> 3 version that you<br />

download.<br />

There are two command-line prompts used in the book, and they are used consistently in their<br />

respective contexts. A single $ is used as the system prompt at which the <strong>Python</strong> interpreter might be<br />

run, while the famous triple chevron >>> is used for interactive <strong>Python</strong> interpreter sessions themselves.<br />

If you are familiar with good <strong>Python</strong> coding practices and with PEP-8, the community's coding<br />

standard, you will note that the program listings here in the printed book deviate in a number <strong>of</strong> respects<br />

from best practices. You can find PEP-8 here: www.python.org/dev/peps/pep-0008/.<br />

I have varied from standard coding style in the interest <strong>of</strong> saving trees and to adapt the code to the<br />

printed page. For example, I <strong>of</strong>ten shamelessly import several modules in a single statement, instead <strong>of</strong><br />

putting each module on its own line. My listings also tend to run commands without performing the<br />

familiar check for whether the script has really been run from the command line:<br />

if __name__ == '__main__':<br />

» ...<br />

This, again, is simply in the interest <strong>of</strong> space and readability. In the versions <strong>of</strong> the program listings<br />

provided in the downloadable source code bundle, I have tried to adopt a coding style closer to PEP-8, so<br />

do not be surprised if those listings look a bit different from the ones you see here in the book.<br />

Your Comments<br />

If you need to contact me directly about anything in the book, my e-mail address is<br />

brandon@rhodesmill.org, and I welcome ideas, questions, or constructive criticism. But you should<br />

submit any errata directly to the Apress web site on the page for this particular book, so that they can<br />

maintain the central list <strong>of</strong> what will have to be revised for the next printing.<br />

Be well; speak respectfully to everyone; write careful tests; and use your newfound powers for<br />

good.Audience<br />

xx

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!