Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Books Media Book Reviews

Foundations of Python Network Programming 144

Sarusa writes "This may be the easiest book review I've ever written. If you program in Python and you want to write Internet applications, go buy Foundations of Python Network Programming by John Goerzen. There. What, you wanted more? Well, okay, but then I'm back to playing Katamari Damacy." Read on for the rest of Sarusa's review.
Foundations of Python Network Programming
author John Goerzen
pages 500
publisher Apress
rating 9 of 10
reviewer Sarusa
ISBN 1590593715
summary If you program in Python, and you want to write Internet applications, you need this book.

First of all, 'Network' means 'Internet.' Everything in the book concerns protocols running over IP, which is almost anything useful these days. That said, this is a lot of ground to cover -- there's FTP, HTTP, POP3, IMAP, DNS, a veritable explosion of acronyms, and this book does a great job of hitting all the ones you're likely to need.

Foundations assumes you already know Python, but nothing about network programming. The first 100 pages covers the basics of IP, TCP, UDP, sockets and ports, server vs. daemon, clients, DNS, and more advanced topics like broadcast and IPv6. And in case you already know all that, how Python deals with them. This is the only part of the book you will probably read in order. After that you pick what you need.

Find a topic you need to know how to deal with, such as using XML-RPC, and locate the appropriate section of the book. There he'll cover the basics of the topic, show you how to use the correct Python module(s) to implement it, explain any gotchas (this is key!), and write a short but functional application or two that uses it. I'm not sure why this book isn't called 'Practical Python Network Programming.' It's eminently Practical. It won't make your heart race, but it tells you exactly what you need to get the job done.

All this information is out there to find for free, but having it all collected and summarized is worth every penny. And the real value is having the edge conditions and not-so-obvious practical details explained by someone who's obviously used this stuff in the field. Python and its excellent libraries make Internet tasks relatively easy, but it's even easier with some expert help, and the libraries assume you already know what you're trying to do. For example, if you're doing a DNS.Request() record query and using a DNS.Type.ANY, it (for good reason) returns information cached by your local servers, which may be incomplete. If you really need all the records you need to skip your local servers and issue a query to the name server for the domain. This is isn't hard; you just have to know what's going on. Or do you know which exceptions can get raised if you're using urllib to fetch web pages? It's here. Exception handling is not neglected.

So you know what you're getting, here's a laundry list of topics: IP, TCP, UDP, sockets, timeouts, network data formats, inetd/xinetd, syslog, DNS, IPv6, broadcast, binding to specific addresses, poll and select, writing a web client, SSL, parsing HTML and XHTML, XML and XML-RPC, email composition and decoding, MIME, SMTP, POP, IMAP, FTP, MySQL/PostgreSQL/zxJDBC (though you won't learn SQL), HTTP and XML-RPC servers, CGI, and mod_python. As a bonus you get some chapters on forking and threading (for writing servers) and handling asynchronous communication in general.

Just to find something to complain about churlishly, I wish Goerzen had managed to do all this and make it scintillatingly brilliant and witty from cover to cover (all 500 pages); perhaps dropping juicy bon mots of gossip from the Debian project. And while I'm at it I'd like a pony. No, seriously. If you program in Python, intend to do anything Internet related, and aren't already a Python networking god, you need Foundations of Python Network Programming. In terms of 'hours I could have saved if only I had this book sooner' it would have paid for itself many times over.


You can purchase Foundations of Python Network Programming from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

This discussion has been archived. No new comments can be posted.

Foundations of Python Network Programming

Comments Filter:
  • Twisted Framework (Score:5, Interesting)

    by BridgeBum ( 11413 ) on Thursday October 14, 2004 @04:56PM (#10528808)
    Another good Python network resource: Twisted Matrix [twistedmatrix.com], a networking framework for Python.

    For those interested in starting in network programming in Python, I'd recommend checking it out.
  • by The Ape With No Name ( 213531 ) on Thursday October 14, 2004 @04:57PM (#10528838) Homepage
    And I see no need to switch to Python. My question is: How easy is it to wrap your code in a library/module and call it your own so you can call it your way? When I tried Python, my first impression was that this was a really readable and relatively easy language to program in, but it just wasn't a Swiss-Army chain saw. You were doing things over and reinventing the wheel all the time. This might have been just me. I admit to being a bigot and a classic pig-headed perl person, but with the nightmare that is Perl6 on the horizon, I need to start considering alternatives.
  • by kevin_conaway ( 585204 ) on Thursday October 14, 2004 @05:00PM (#10528875) Homepage
    I learned perl before I learned python and I found that the OOP constructs in python were better than perl. In perl they just feel bolted on while in python, they are built in from the ground up. Other than that, not much difference in my opinion
  • by mslinux ( 570958 ) on Thursday October 14, 2004 @05:05PM (#10528926)
    I use Python to administer computers... lots and lots of computers. It runs on Macs, Windows, Linux and all variants of Unix. It's one of the most portable languages around.

    I used to be a huge Linux buff (and still am when it comes to servers), but intelligent tools like Python make using Windows XP Home a much more fruitful and fun experience as I can actually get stuff done programmatically. Go Python developers and keep up the good work!!!
  • by ultrabot ( 200914 ) on Thursday October 14, 2004 @05:09PM (#10528968)
    Incidentally, Civilization IV is going to be moddable with Python [civfanatics.com]
  • by ultrabot ( 200914 ) on Thursday October 14, 2004 @05:16PM (#10529033)
    Also I really like how functions are first class objects (meaning you can pass them to/return them from functions)

    And classes too. What's more, a class is just a callable object that is called exactly like a function - "C()" - and it returns an instance of that class. If a function wants a class for instantiation, you can just pass a factory function that returns some instance of any class.
  • by pnatural ( 59329 ) on Thursday October 14, 2004 @05:43PM (#10529326)
    Also I really like how functions are first class objects (meaning you can pass them to/return them from functions)

    And classes too.


    Yes, absolutely. First-class functions and types is one of the most important hallmarks of a good, usable language. Not being able to pass around classes or functions would severely limit how most of my solution sets are defined. Personally, I won't consider languages that don't offer this.
  • Re:Typos (Score:4, Interesting)

    by legirons ( 809082 ) on Thursday October 14, 2004 @06:14PM (#10529611)
    "Also my binding broke after a week"

    As practicalities go, the one thing I really liked about the last APress book I got ('Dive into Python') was that when I wanted to refer to it at work, I didn't have to carry the book in, I just read the section I wanted on their website.

    It was one of those "never going to buy another book without this facility" moments... how could we have missed something so useful for so long?

    So back on topic, this book only has one chapter available for download, and it's in PDF rather than anything useful, so I guess it's not general policy to make all APress books downloadable.

    I did find it amusing how Visual Basic, C#, and .NET each get their own top-level section at the APress website, while PHP, Perl and Python are down in the "Open-Source" section next to books describing products (Apache, Linux, Plone, MySQL, etc.)
  • by Anonymous Coward on Thursday October 14, 2004 @09:09PM (#10530940)
    For anybody who has had to deal with this wretched monstrosity, python is a blessing thanks to the SOAPpy package.

    The usual way involves a pageful of obscure code, and having to use obtuse WSDL descriptor files and code generators to give you classes.

    But, hey, python can generate classes and methods on the fly. So getting the temperature at zip code 90210 becomes a one-liner after some standard imports:

    SOAPpy.WSDL.Proxy('http://www.xmethods.org/sd/2001 /TemperatureService.wsdl').getTemp('90210')
    I'm not kidding; that line currently returns the floating point number 68.0.

    Note: you'll need to remove the extra space in the URL that the slashdot antilameness crud inserts. The full example is found in simpleWSDL.py in that package.

  • by Anonymous Coward on Friday October 15, 2004 @12:43AM (#10532313)
    Try a few declarative languages, like Haskell (functional) or Prolog (logic).

    You're a little bit off there. Haskell is not declarative. It's just functional, as you said. Prolog is declarative though.

    If you want to try a nice variety of languages here's what I suggest:

    C - 'nuf said.

    Java or C# - Good application programming languages. Similar enough for learning purposes that it doesn't matter which you use. If you want to get into the inner workings, both are very interesting systems to learn about.

    Perl or Python - They're not too similar as languages, but their purposes are similar. If you want to do scripting, these are good choices.

    Haskell - Purely functional language. As expected from a purely functional language, things like I/O are difficult in Haskell. Still, an excellent way of learning a whole new way to think about programming.

    Prolog - Nice declarative language. Thinking in first-order logic is another thing you don't do with common languages. Better get used to it though, since between the semantic web, Spotlight, WinFS, and other metadata, programs are going to have a lot of logical reasoning to do.

    Assembly - Sure, you can survive without this these days, but knowing what's going on at the very lowest level gives you a new perspective on programs. It can also help when things go really really wrong with your program and you're not sure you can even trust the VM any more. Save your sanity. Don't look at x86. I suggest MIPS.

    awk and sed - Yes, the classics. It doesn't hurt to look at all the common unix tools, but these are the big boys of string processing. You'll need to learn the basic of regexes at some point, and if you don't use Perl, this would be the place to do it.

    Optional:

    C++ - It's not dead yet. Personally I don't know C++, but most apps out there are still using it, so it's inevitable that I, and you, will see it some day. If you know C and Java/C#, you should be able to read C++ at least.

    Smalltalk - It never hurts to study the classics. Also, the distinct lack of ancestry from C that Java and C# have can make it easier to figure out how that whole object-oriented thing is really supposed to work.

    BASIC or Cobol - You study Smalltalk to understand how good things could be. You study these to understand how bad they could be.

    Lisp - Possibly as an alternative to Haskell. Another classic, and a little more practical than Haskell. I think Haskell is still a better teacher of functional programming, but take your pick.

    Fortran - Do you do numerical methods? Then be sure to try Fortran. Just as C is close to the machine, Fortran is close to the math. I can't guarantee you'll like it, but it's worth a look.

    Ruby - I think of this language as just plain fun. It has so much syntactic sugar you could bake it into a cake. Be warned, you may end up liking it even more than Perl or Python.

    XUL, XAML, or X Forms - I can already hear people saying "What the heck?" This is just my own personal opinion, but declarative UIs are the way to go. How many people would seriously still write them procedurally anyways? Interface Builder, Visual Studio, HTML...people already "build" UIs anyways. I think there's benefits in a rich UI language that's both human and machine readable, hence, I suggest one of these...

    XSL - awk gone XML with a few imperative features. Unless you think you will never ever touch XML, learn this. Especially learn this if you think XML is a silly idea. I would generally agree, except some great tools have been created because of it.
  • Python == good (Score:3, Interesting)

    by mcrbids ( 148650 ) on Friday October 15, 2004 @02:32AM (#10532770) Journal
    I spent some time learning a bit of Python, only to abandon it. Not because of Python, but because I had too much inertia going in various PHP projects that pulled me back.

    Python caused me to change my layout for code, almost instantly eliminating a big problem with c-like code: the missing brace.

    Most code is structured like this:
    Function fubar {
    statement a;
    do (b);
    if (c()) {
    performfunction(x);
    }
    }
    In this small segment, notice that there are to sets of braces - and they don't line up at all. You have to mentally follow the code after "fubar" and see that after the condition "if (c())" in order to mentally track the state of the braces.

    Compare this to
    Function Fubar
    {
    statement a;
    do (b);
    if (c())
    {
    performfunction(x);
    }
    }

    (slashdot's ECODE filter sux0rs)

    If you could see it, you'd notice that the braces line up. The opening and closing braces for the condition "if (c()))" are indented one more than the braces for function Fubar() which are indented more than the line "Function fubar()" itself.

    Thus, you merely have to follow the indents to match the opening/closing braces. As a result of this change, I spend less than 5 minutes per week matching up braces without the need for an IDE to match them up for me.

    Python seems to be a good language (I like that you can compiles sections of a Python program in c to improve performance without rewriting the whole program) but it's concepts of layout certainly carry beyond Python itself!

  • by juhaz ( 110830 ) on Friday October 15, 2004 @12:55PM (#10536728) Homepage
    from sys import stdin
    print "Who are you?"
    name = stdin.readline().strip()
    print "I'm glad to meet you, %s." % name


    Overly verbose and complicated, you can write this in two lines and save an import as well as the need to know stdin is a file object to boot. And string formatter operator is not instantly clear, especially to a person who hasn't used printf(), not everyone has C background.

    How about
    name = raw_input("Who are you? ")
    print "I'm glad to meet you, " + name

"Gravitation cannot be held responsible for people falling in love." -- Albert Einstein

Working...