Forgot your password?
typodupeerror
Programming Books Media Book Reviews IT Technology

Python in a Nutshell 246

Posted by timothy
from the panicking-the-nuts dept.
Ursus Maximus contributes this review of Python in a Nutshell, writing "Perhaps the best book about Python ever written, this is the perfect capstone to anyone's library of Pythonic books, and also the perfect introduction to Python for anyone well versed in other programming languages. For newbies to programming, this would still be a good second book after a good introductory book on Python, such as Learning Python by Mark Lutz." Read on for the rest of his review.
Python in a Nutshell
author Alex Martelli
pages 636 pages
publisher O'Reilly
rating Excellent, superb, 5 stars
reviewer Ron Stephens
ISBN 0596001886
summary Complete reference book for the Python programming language

Written by my favorite author and Pythonista, Alex Martelli, this book manages to fill three roles in extremely pleasing fashion. First and foremost to me, it is a great read, straight through. Mr. Martelli's prose is always sparkling and always keeps the reader interested. No matter how many Python books you have read, you will learn some nuances from this book, and it is about the best review of the whole Pythonic subject matter that I can imagine. While there is absolutely no fluff whatsoever in these 636 pages, it still makes for rather easy reading because the explanations are so clearly thought out and explored as to lead one gently to understanding, without in any way being verbose. It is obvious that Alex Martelli took his time and put in sufficient thought, effort, and intellectual elbow-grease to make this work a classic for all time.

Secondly, this book is the ultimate Pythonic reference book, the best fit to this role I have yet seen. You will keep this book in the most cherished spot on your book shelf, or else right at your side on your computer desk, because you can almost instantly find any topic on which you need to brush up, in the midst of a programming project.

Third, Python in a Nutshell is the most up-to-date book on Python (as of April 2003) and includes the best and most complete expositions yet on the new features introduced in Python 2.2 and 2.3. These topics are not only covered in depth, they are integrated into the text in their proper positions and relationships to the language as a whole. They are explained better here than I have seen anywhere else, so much so as to make them not only understandable to me (a duffer), but indeed so that they appear seamlessly Pythonic, as if they had been a part of the language since version 1.0. Topics explored in depth include new style classes, static methods, class methods, nested scopes, iterators, generators, and new style division. List comprehensions are made not only comprehensible but indeed intuitive.

The book is surprisingly complete. It covers the core language as well as the most popular libraries and extension modules. It is difficult to choose any one portion of the book to highlight for extra praise, as all topics are treated so well. It is a complete book, the new definitive book about Python.

Everything about this book speaks of quality. In addition to the top notch writing and editing, O'Reilly really did the right thing and published this book printed on the highest quality paper, paper so thin that the 636 pages are encompassed in a book much thinner than one would expect for such a size, but strong enough to resist wear and tear. The text is most pleasing to the eye. Holding the book, and turning its pages, gives one a feeling of satisfaction.

Any job worth doing is worth doing well. Alex Martelli and O'Reilly have done justice to a topic dear to our hearts, the Python programming language. Perhaps, in years to come, the passage of time may make this book to be no longer the most up-to-date reference on the newest features added to Python. But time can not erase the quality craftsmanship and the shear joy of reading such a well thought out masterpiece of Pythonic literature.


You can purchase Python in a Nutshell from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page. Ron Stephens would also like you to check out Python City, with "27+ reviews of books about Python. 67+ links to online tutorials about Python and related subjects Daily newsfeed of Pythonic web articles, new sourceforge projects, etc."

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

Python in a Nutshell

Comments Filter:
  • Nutshell?!? (Score:5, Funny)

    by skillet-thief (622320) on Wednesday April 16, 2003 @11:48AM (#5744135) Homepage Journal
    634 Pages!?!

    That's a pretty goddam big nutshell, if you ask me!

  • by Anonymous Coward
    Official Gentoo-Linux-Zealot translator-o-matic

    Gentoo Linux is an interesting new distribution with some great features. Unfortunately, it has attracted a large number of clueless wannabes who absolutely MUST advocate Gentoo at every opportunity. Let's look at the language of these zealots, and find out what it really means...

    "Gentoo makes me so much more productive."
    "Although I can't use the box at the moment because it's compiling something, as it will be for the next five days, it give

  • by campbellkid (663975) on Wednesday April 16, 2003 @11:50AM (#5744144)
    The reviewer assumes either that we have already read one of the earlier editions, or that we can read his mind. Asside from the discussion about how nice the paper is, I don't know what sets this book apart from other Python books.

    Could the author please respond in this thread and give some examples of the new content, rather than just "covers it all"?

    • by josephgrossberg (67732) on Wednesday April 16, 2003 @12:41PM (#5744478) Homepage Journal
      Heh. Apparently he was too busy sucking Alex Martelli's c0ck to write any more details.

      I mean Martelli's the man and all, but don't drop shit like:

      * "Perhaps the best book about Python ever written"
      * "my favorite author ... Alex Martelli"
      * "Mr. Martelli's prose is always sparkling and always keeps the reader interested"
      * "It is obvious that Alex Martelli took his time and put in sufficient thought, effort, and intellectual elbow-grease to make this work a classic for all time."
      * "You will keep this book in the most cherished spot on your book shelf"
      * "It is difficult to choose any one portion of the book to highlight for extra praise, as all topics are treated so well."
      * "Everything about this book speaks of quality."
      * "Holding the book, and turning its pages, gives one a feeling of satisfaction."
      * "Time can not erase the quality craftsmanship and the shear joy of reading such a well thought out masterpiece of Pythonic literature." ... under the premise of objectivity.

      People want to know "What's good and bad about this book" and not "How many ways can I kiss ass".
  • by WIAKywbfatw (307557) on Wednesday April 16, 2003 @11:52AM (#5744164) Journal
    You know, when I saw that title, I just knew that there was a joke in there involoving Monty Python, nuts and hell (nutshell, nuts hell).

    If I had the time I'd come up with it, and I'm sure it would be the funniest joke in the world, much better than the German joke, "two peanuts were walking down the street and one was assorted".

    Unfortunately, I have to go out for a silly walk, and then onto a mouse club, so I'll have to leave it to someone else to inject some much needed hilarity into these proceedings.
  • by Anonymous Coward on Wednesday April 16, 2003 @11:52AM (#5744165)
    Let me start off by saying that I don't usually read this site. I was pointed here by a python programmer who wanted more python people to join this dicussion. However I'm not exactly a "python person." I'm most comfortable in C, with a smattering of Java, Perl, Asm, Lisp and Python (in no particular order). That being clarified, I'd like to say a few words.

    First of all, I don't want to offend anyone, but Perl really is an example of the most horrible way to design a language. I say "design" with tongue-in-cheek, because the language wasn't really designed so much as thrown together from pieces of odd scripting languages (many of which should have been put to rest long ago). The implementation itself is rather unfortunete; because of how it's built you can't really implement perl in terms of itself (well I suppose you could, but not with a slight measure of self-respect), the entire system needs to be scrutinized by security experts before any program written in Perl can be considered secure, and it is doubtful that Perl will ever be re-implemented ever again.

    That being said, Perl is at least useful for many things ("practical," I believe it's called). People always tell me how they use it for system-administration tasks (for some reason I don't seem to engage in enough adminitration tasks to require perl's help, or if I do they're all suitibly mundane), and it does have an impressive ability to cope with string data (not something I'd base a language on, but at least it stopped people from using SNOBOL).

    Now Python on the other hand is almost completely a different story. It's supremely orthagonal and elegant in its design, with support for functions as first-class types, an enforcement of clean coding standards through whitespace sensitivity (most Perl coders object vehemently to this because it infringes on their ability to write really ugly code), etc.

    But the problem is that Python suffers from a lot of Perl's problems and adds a few of its own: you can't implement it in itself, it has no strong typing (even Perl's use strict is ridiculously better), an OO system with no support for data hiding, etc. etc. And that brings me to the biggest problem: Python doesn't really have a niche to fill. The CGI space has been seemingly co-opted completely by Perl (at least until people start using PHP), and it's too dog-slow to be used for real CS applications. As a beginner's language it's ideal, but that's not going to help it be taken seriously when it comes to real computing tasks.

    If the python developers made some tweaks to the type system and added a real compiler, then I would advocate that most software engineering be moved there. As it stands it's an original language which is a lot of fun to program in, and still has lots of unmapped potential to it.

    So where does that leave us, now that I've managed to piss EVERYBODY off? Well, I guess I conclude by saying that if you read this and got a sudden urge to throw a molotov cocktail through my window, then you're really taking one language too seriously. If you blind yourself so much that you can't see the faults in Perl or , then you're really no use to anyone in your community, in particular the users who depend on you to build solid, well-rounded applications. Don't be a Python zealot or a Perl zealot; be a programming zealot, learn as many languages as possible, and which one to use in a given situation. That's all I have to say.
    • Perl v. PHP (Score:2, Insightful)

      by Anonymous Coward


      The CGI space has been seemingly co-opted completely by Perl (at least until people start using PHP)

      what, PHP doesn't suffer from the same problems as perl? whitespace? data hiding? real objects?

      people use these languages because the fluidity at which they can be written (albeit crappily). conversley, a good programmer will write good code regardless of the pro-active design constraints imposed by the language.

      etc.

      excellent troll btw!

    • by raju1kabir (251972) on Wednesday April 16, 2003 @12:10PM (#5744276) Homepage
      But the problem is that Python suffers from a lot of Perl's problems and adds a few of its own

      The biggest problem with Python, IMHO, is the online documentation. It's the worst I've ever seen, so abstract that it's of no use to anyone except maybe as a reference for someone who wants to write real documentation.

      I can only assume that like Python itself, the documentation is the result of an author who wanted to do things "the best" way, without being willing to look outside his own head to determine what that might be. For the language itself, the result was okay - if slightly annoying at times. For the documentation, it's unacceptable. New and different languages can be learned. But with indecipherable and oddly-organized documentation, that's very difficult to even start doing. I had several "false starts" with Python, abandoning it quickly because the documentation (and installation process) were so opaque. If not coerced by my employer into giving it another try, I never would have touched it again. The only reason I stuck with it this last time was because my employer had a stack of Python books for me to use.

      In the "heavy scripting" domain, I've put a lot of time into Perl, Python, and PHP. PHP's online documentation is the exact opposite of Python's; entirely focused on the practical, with lots of examples and very little theory or background. Perl's is somewhere in the middle. Overall, as a learner I found Perl's documentation to be the best, and as an advanced developer I find PHP's to be supreme, bar none. Python's is a disgrace, useful to neither beginning nor advanced users.

      It's great that people are writing good books about the language. But in this day and age, it shouldn't be necessary to buy a book just to make sense of an open-source tool.

      • by Anonymous Coward
        I couldn't agree more w/ both this post and the one before it. I have yet to find a use for Python that isn't already covered by a language I know (PHP for web apps, Java for more complicated server or GUI stuff), and the few times I have tried to learn more about Python, I run up against the online documentation, which does more to talk about how cool Python is than actually explain how to use it (just like you said - the opposite of PHP's online documentation, which is hands-down superb). This isn't meant
        • I really don't see what the problem is. I learned Python TOTALLY from the documentation that is included with the Python package. I went through the tutorial to get the 'flavour' for the language, then browsed the library documentation to see what kinds of libraries there were, and the same with the language documentation. I go back to the library and language documentation when I need more information.

          It's, for the most part, fine.

          Yes, there ARE some holes here and there, as there are with a lot of the
          • I too don't think that Python's documentation is bad, in fact I actually think that its excellent. Much like the K&R C book. One thing that I admire about Pythons documentation, is that you could recreate the language from "Language Reference" section.

            I find that there are 2 (if not many more) kinds of documentation. Documentation that is meant to be read (more like a book), and documentation that is meant to be used (looked up while using like manpages and msdn). I believe that Python is that of t
      • by Anonymous Coward
        I didn't have this experience at all, I found a lot of their documentation very helpful and certainly more helpful than the free documentation on Perl that you can find.

        I didn't have any problem with false starts, I went to the python website one day to check it out and the next day I went to one of the online books about python they linked to and I learned a shitload and within a couple hours I began to appreciate and love Python.
      • > Overall, as a learner I found Perl's documentation to be the best, and as an advanced developer I find PHP's to be supreme, bar none. Python's is a disgrace, useful to neither beginning nor advanced users.

        Yep, I've come to those exact same conclusions. Take a look at the "win32*" API docs hosted at ActiveState, for example win32net.DriveAdd()

        The docs basically say "Wrapper for the win32 call -- see MSDN for details".

        No examples of usage? Thanks! OK, I go to MSDN and see a C data struct for arguments
    • by Ed Avis (5917)
      I've been using Python for a few months now. I hope people won't mind if I post a shopping list of what seem to be missing features in the language, and ask if there is a way round them.

      - Python has 'break' and 'continue' like C. But these only affect the innermost loop. Is there a way to break out of an enclosing loop? (In Perl you can label a loop and then say 'next LABEL', etc.)

      - Failing that, is there a way to get goto statements in Python? They can sometimes be an elegant way to express somethin
      • The exception mechanism provides a way for you to break out of multiple loops if there is not already an elegant way to express your loop. Also, the else clause for loops can be useful in some cases.

        Objects are already passed by reference. You can't change strings because they are an immutable type. If you need references, you can use the weakref module, or create your own wrapper class (delegating accesses to the underlying object).

        you can define named functions in-line, that work as closures (i. e. usin
      • by Kidbro (80868)
        - Python has 'break' and 'continue' like C. But these only affect the innermost loop. Is there a way to break out of an enclosing loop? (In Perl you can label a loop and then say 'next LABEL', etc.)

        Usually solved by a try/except clause when needed - which it seldom is.

        - How can I pass a variable by reference?

        EVERYTHING is a reference. You pass nothing but references. If you call foo(bar), foo will have a reference to the exact same object as bar pointed to. The fact that you can not modify a string p
      • by Frater 219 (1455) on Wednesday April 16, 2003 @12:31PM (#5744404) Journal
        Python has 'break' and 'continue' like C. But these only affect the innermost loop. Is there a way to break out of an enclosing loop? (In Perl you can label a loop and then say 'next LABEL', etc.)

        Like Java and Lisp -- and unlike Perl -- Python has exception handling. The structured way to get out of an inner loop is the same as the structured way to get out of a deeply nested function call: raise an exception, and trap it at the higher level where you want to "go to".

        How can I pass a variable by reference? For example, to take a reference to a string, pass it to a function and have that function modify the string passed in. More generally, is there a way to store references?

        In Python, everything is a reference, but strings are immutable objects. There's no such thing as "modifying the string passed in" -- all the built-in string functions return a new string. However, for mutable types such as lists and dictionaries, functions can certainly modify their arguments, as in this example:

        def foo(lst): lst.append("beer")
        y = ["wine"]
        foo(y) # y is now ["wine", "beer"]

        Python advertises its support for first-class functions, but I can't seem to get closures to work. The 'lambda' keyword won't accept assignment or even sequencing inside the function body.

        Especially since I have some Scheme in my programming background, this is a quirk I find annoying about Python: lambda is underpowered. It's comparable to the old BASIC "DEF FN" in that it allows only expressions, not statements, in the lambda-body.

        However, you can do what you want by defining a function with a temporary name, using def, and returning it. (In Python it is perfectly valid to have function definitions inside other function definitions, and it does what you expect: defines functions whose names have local scope, but can be returned.) You can also create callable classes, which act like functions instead of object factories. There's an implementation of curry for instance in the Python Cookbook, which does this. Check it out. [activestate.com]

        Is there a do/while statement in Python? Plain 'while' is there but occasionally an 'at least once' loop is what you need. Is there an addon package or library for Python that provides a 'do' construct?

        There is neither a do/while nor a repeat/until in Python. Again this is something I don't agree with, but the argument is that this keeps the number of redundant keywords down. The convention is to use while loops and escape with break when necessary.

        • Like Java and Lisp -- and unlike Perl -- Python has exception handling.

          Perl has exception handling with die/eval. Here is an article [perl.com] about it.
          • Perl has exception handling with die/eval.

            If you're going to use it for that, take a careful look at the documentation for eval: notably, what do you want to do with __DIE__ hooks? There's more than a bit of anti-structured "action at a distance" going on there.

            Something else to note is that Python and Java exceptions work hand-in-hand with the call stack, and provide useful stack backtraces if you bomb out. ISTR backtraces are an extra you have to ask for in Perl -- the Carp module's confess, if

        • Thank you for your response and to the several others who also replied. I've chosen to reply to yours since it seems the most detailed.

          Exception handling to break out of a loop - hmm, yes, I hadn't thought about that. It does seem a bit OTT to raise and catch an exception just for that - a whole 'try/except' block when a simple 'continue LABEL' would have sufficed - but whatever.

          OK, I think I understand what is happening with strings. If they are immutable then there is no way to implement a function l
          • If they are immutable then there is no way to implement a function like Perl's chomp() which modifies the string passed in.

            That's right. The equivalent in Python is "foo = rstrip(foo)", which does rebind foo to a new string.

            This prints '50', showing that g() cannot access the variable in its enclosing scope.

            What you did was create a new name x, local to the scope of g.

            If what you're after is to retain data among several calls, a class is probably what you want. It can be callable (as in the c

          • def f():
            x = 50
            def g():
            x = 40
            g()
            print x
            f()

            > This prints '50', showing that g() cannot access the variable in its enclosing scope.
            > It's not a closure in the true sense.
            > The only way I could find to make this work was to resort to global variables - gah!

            That's the intended behaviour. You can make x
            a static variable of f:

            def f():
            f.x = 50
            def g():
            f.x = 40
            g()
            print f.x
            f()

            If you don't want it static, create a new object
            to hold it (or store it on g, etc).
          • Actually, as of Python 2.2, with nested scopes [python.org] implemented, g() can really access the variable outside its own scope.

            The problem though is similar to what you alluded to with passing variables into functions and wanting the functions to modify them; when in the inner function you say "x = 50", you're rebinding the local-to-g version of x. The end result is that the outer x is then not repointed to the new object. (See the PEP for why, or look at the appropriate part of the "what's new" document [python.org])

            In any c
        • In Python, everything is a reference, but strings are immutable objects. There's no such thing as "modifying the string passed in" -- all the built-in string functions return a new string.

          FWIW Guido has said that in Python 3 (still a ways off) that all strings are going to be Unicode, and for binary/byte data they'll be a buffer object (I don't think related to the current buffer object) that will be mutable, since this is typically more useful for byte data. For now strings of bytes and strings of char

      • by tal197 (144614) on Wednesday April 16, 2003 @12:36PM (#5744440) Homepage Journal
        Python has 'break' and 'continue' like C. But these only affect the innermost loop. Is there a way to break out of an enclosing loop?
        Throw an exception and catch it whereever. Eg:
        try:
        __while ...
        ____while ...
        ______raise FinishLoop
        except FinishLoop: pass

        How can I pass a variable by reference? For example, to take a reference to a string, pass it to a function and have that function modify the string passed in.
        Everything is always passed by reference. You can't modify a string because strings are immutable.

        The 'lambda' keyword won't accept assignment or even sequencing inside the function body. So anonymous functions you might want to pass around can't do much beyond trivial operations.
        lambda is a short-hand for def. Use that if the body isn't a simple expression:

        def make_print(message):
        __def new_fn(): print message
        __return new_fn
        make_print('Hello')()

        Is there a do/while statement in Python?

        while 1:
        __# Stuff
        __if finished(): break

        Some python tutorials I wrote:

        Python for BASIC programmers [sourceforge.net]
        Writing GTK applications in python [sourceforge.net]

        • You can 'fake' 'pass by reference' by passing a list instead. Viz:

          def fn (a):
          _ a[0] = 'Goodbye'

          a = ['Hello']
          fn (a)
          print a # This will print goodbye

          However, it's VERY rare that you need to use pass by reference. Instead, consider using multiple return values.

          (Underscore used to force indentation)
        • Throw an exception and catch it whereever. Eg:

          try: __while ... ____while ... ______raise FinishLoop except FinishLoop: pass

          Dude... that's disgusting, not to mention raping the exception system. Exceptions are meant to handle errors. PHP fixes the break/continue problem by giving those operators a parameter. So if you want to continue 2 loops up, you say "continue 2;".

          Gah. Now I know why I don't use Python.

          • How is it "raping the exception mechanism"? Can you point to a case where it could cause a problem or harm readability?

            "continue 2" on the other hand, almost makes me puke, requires a lot more careful tracking of changes in the code, and makes every piece of code tightly-coupled with every other.

            Puke. Now I know why I don't use PHP.
    • Don't be a Python zealot or a Perl zealot; be a programming zealot, learn as many languages as possible, and which one to use in a given situation.

      You have a point there, but I'd put it in a slightly different way. I'd not tell people to learn as many languages as possible, but rather learn programming and its basics (knowing the architecture behind the scenes, the CPU, is really a lot of fun).

      There isn't much point in knowing every programming language, but a much better deal to know the syntax used in
    • by tuffy (10202) on Wednesday April 16, 2003 @12:19PM (#5744338) Homepage Journal
      And that brings me to the biggest problem: Python doesn't really have a niche to fill.

      In general, I've noticed Python makes writing programs very fast and very easy to modify later to add new features. It takes me a little longer to write equivilent programs in Perl, but the Perl programs probably run a little faster although they take a bit more effort to modify later. Finally, if I really need a program to run very fast, I can port it to C where it'll run extremely fast, but that will naturally take the longest to write and modify.

      Having said all that, I use Python programs for those day-to-day administration duties where plenty of tweaks are required. Python works great for CGIs too, and should scale up to a reasonable load. But, if speed or extreme scalability are a requirement, porting a Python prototype over to C is often a good idea. Still, I have no shortage of tasks that require quick programming but don't require great speed - and Python fits those quite well.

      But if I could compile it to native code, now that would be pretty sweet.

      • Python's niche (Score:2, Interesting)

        by vivek7006 (585218)
        Python is an excellent rapid prototyping language. Because of its neat syntax and simple philosophy, programmers can quickly create a working protoype in Python. Later, if needed, it can reimplemented in a faster programing language (like C++).
      • by frehe (6916)

        If you need more speed than native Python provides, you can always write code in C and wrap it so it is callable from Python. The wrapping is really easy to do, once you have understood the general concepts involved in it. The product I currently work on has about 10000 lines of C code (crypto and networking) which is used this way, and it works perfectly. For more information about extending Python with C, see:

        Extending and Embedding the Python Interpreter [python.org]

        Python/C API Reference Manual [python.org]

    • But the problem is that Python suffers from a lot of Perl's problems and adds a few of its own: you can't implement it in itself, it has no strong typing (even Perl's use strict is ridiculously better), an OO system with no support for data hiding, etc. etc

      Actually, one of these is being worked on: There's an active project to write Python in itself. I believe they're taking the same tack as Squeak.

      John Roth
    • by bbum (28021) on Wednesday April 16, 2003 @12:28PM (#5744394) Homepage
      But the problem is that Python suffers from a lot of Perl's problems and adds a few of its own: you can't implement it in itself, it has no strong typing (even Perl's use strict is ridiculously better), an OO system with no support for data hiding, etc. etc. And that brings me to the biggest problem: Python doesn't really have a niche to fill. The CGI space has been seemingly co-opted completely by Perl (at least until people start using PHP), and it's too dog-slow to be used for real CS applications. As a beginner's language it's ideal, but that's not going to help it be taken seriously when it comes to real

      Uhh.... you are seriously misinformed.

      data hiding: trivial to implement by overriding the standard accessors and limiting the set of things that can be accessed externally. Since you have full access to the scope and stack, you can even limit things in a fashion similar to java's private/public/protected. I have used this many times to force attributes to be set only through a particular path that involves certain chunks of business logic.

      implement it in itself: Not sure what your point is, but you can certainly implement the Python VM in itself. The Python VM is actually quite portable as is demonstrated by the excellent Java based implementation found in Jython.

      strong typing: yes -- python has no strong typing, but it is trivial to check types and constrain APIs to particular types. At times, it would be nice to have strong types, but weak typing also has some extremely powerful uses and patterns.

      Too dog slow? Uh, no. See the Twisted project for an example of an "internet event server" whose web server implementation is faster-- and more flexible-- than apache. Not that apache is fast, mind you, but something that is faster than apache while maintaining flexibility can certainly claim to have better performance than the server used by, what, 50+% of the world's web servers?

      Python scales well, it is extremely reliable, and has excellent performance for an interpreted language. Python is used in many mission critical situations in both commercially saleable products as well as in embedded markets.

      Personally, I have built trading systems in Python. If you have ever been around a Trader when their technology doesn't work, you know that using technology that is fundamentally broken is exceedingly unpleasant (unless you enjoy being yelled at and having heavy things thrown at you). Python proved to be extremely reliable and allowed us to roll out new versions of the software very rapidly.

      Note that I am not a Python Zealot -- I program in some random combination of Python, C, Objective-C, Java and Lisp on a daily basis. Of all the languages, I prefer to use Python because I can get things done more quickly and with lower maintenance costs than any of the other languages. However, I'm not going to berate a client simply because they insist on using Java-- and certainly not if they have a good reason for doing so....
    • I'd have to say that more than a few people [php.net] are using PHP. In fact, of the available Apache modules, guess which one is the most popular [securityspace.com]? (Hint: it's not PyApache or even mod_perl by a long shot)

    • by mbaranow (610086) on Wednesday April 16, 2003 @12:57PM (#5744594)
      My own opinion, like yours, is biased by the specific problem domain I applied Python to. For me that has been sys-admin scripts and network/cgi automation scripts.

      How is the ability to write a Python compiler in itself practially relevant to most users?

      Lack of strong typing and no support for data hiding can be thought of as a feature by those so inclined. This is just analogous to objections against 'whitespace sensitivity'.

      I more closely agree with one of the replies: that Python suffers from horrible documentation. I recommend looking at ActiveState Python for a slight improvement from the web manual.

      Some _personal_ highlights using python:

      - learning curve duration: 1.5 hours to start writing moderate complexity RE file parsing scripts.

      - ability to write a cgi enabled http server in approx 3 lines of code

      - ability to write a decent cross-platform opengl demo in approx 200 lines of code. using PyGame, PyOpenGL, Numeric etc.

      Also, please just ignore the zealots, don't acknowledge them with so much disclaimer.

      all the best,
      mbaranow
    • Now Python on the other hand is almost completely a different story. It's supremely orthagonal and elegant in its design, with support for functions as first-class types, an enforcement of clean coding standards through whitespace sensitivity (most Perl coders object vehemently to this because it infringes on their ability to write really ugly code), etc.

      Sorry, but this is just baiting. My problem with a lack of block endings is that it makes it hard to see a complete or incomplete block when there is a

      • Your blocks are obviously too large, then.
        You need to divide into smaller, more trivial pieces of code.

        Python is so expressive that functions/methods rarely need to exceed 5-8 lines.

        Show me any example of a long Python function where you have experienced what you speak of, and I'll explain how and why its too long.
    • That being said, Perl is at least useful for many things ("practical," I believe it's called).

      Python is useful for many things as well, as evidenced by the number of people who use it, including Boeing, Disney, Hewlett-Packard, Industrial Light & Magic, Intel, JPL, Lawrence Livermore Labs, NASA, and Yahoo. Programmers at places like these are usually allowed to make their own decsions about their tools, and they chose Python. These guys are good. They don't use tools that they don't like. This is no

    • But the problem is that Python suffers from a lot of Perl's problems
      Other than Performance?

      and adds a few of its own: you can't implement it in itself
      Hmm? Its quite trivial to parse Python code in Python, and its qutie trivial to interpret it with Python code, so where's the problem?

      it has no strong typing (even Perl's use strict is ridiculously better),
      You're confusing "strong typing" with "static typing". Python has no Static Typing, but indeed has Strong Typing (try '5 + "Hello"' in your Python interpreter). Perl, on the other hand, has no strong typing at all ("Hello" + 5 is perfectly valid in Perl, albeit senseless).
      Not having Static Typing is not a bad thing - its a concious decision by the language designers. The designers of Python wanted the language to be just-explicit. If you want the program code to express an idea, you express it once - Which is more than implicit, and less than redundant. Static typing is redundant - and avoided in Python as a design goal of minimizing programming time of any task.
      Another idea behind the lack of static typing is that all lines of code MUST run at least once anyway for any minimal level of reliability, so the compilation-level check adds no value.

      an OO system with no support for data hiding, etc. etc.
      Python supports data-hiding, but simply does not enforce it. This is because Python is not a BDL (Bondage and discipline langauge). Instead, there are extremely well-established and documented Python conventions. The prefix underscore that denotes private/protected, The double underscore that
      denotes private (avoiding namespace clashing by name mangling), etc.
      And that brings me to the biggest problem: Python doesn't really have a niche to fill. The CGI space has been seemingly co-opted completely by Perl (at least until people start using PHP), and it's too dog-slow to be used for real CS applications.
      Python isn't a niche language. Its a general-purpose language - and no - its far from being too slow for real CS applications. That's why its successfully used in Search engines, 3d engines, system administration, compilers, games, etc.
      As a beginner's language it's ideal, but that's not going to help it be taken seriously when it comes to real computing tasks.
      Python is taken very seriously in many many places, with increasing seriousness.

      If the python developers made some tweaks to the type system
      Like what? Static typing conflicts with the Python design goals.
      and added a real compiler
      Python already has the Jython compiler to Java, psyco compiler to native code, and others.
      then I would advocate that most software engineering be moved there.
      Many already advocate it for all software engineering except for the inner loops which are exported to Python from C code. This proves for many people to be the most effective way to write fast, reliable maintainable code.
      As it stands it's an original language which is a lot of fun to program in, and still has lots of unmapped potential to it.
      The unmapped potential is discovered by more people every day :)
  • Very Pythonic (Score:3, Informative)

    by Limburgher (523006) on Wednesday April 16, 2003 @11:55AM (#5744181) Homepage Journal
    I liked this review. Sparkling, fluffless and pythonic. Adjectival as well.

    Also, in response to an earlier post, the fries are spelt Julienne. And are damn tasty.

  • by Ed Bailey (1912) on Wednesday April 16, 2003 @11:55AM (#5744184) Homepage
    ...I found New Riders Python Essential Reference to be a far better introduction to the language. I eagerly waited for Python in a Nutshell to come out, but I found I kept gravitating back to my copy of Essential Reference (the second edition, btw).

    I am normally never disappointed with an O'Reilly book, but I was in this case. I hope it's not the start of a trend for them...
    • The Essential Reference is OK, but the version I have (Update to Python 2.1) the page numbers "drift" from the index and table of contents. After about halfway through the book, all index and TOC entries are off by at least a page or 2. This is more than mildly annoying when I am trying to look something up.

      It looks to me like when they "updated to Python 2.1", they forgot to also upgrade to "book 2.1". Fair warning!
    • Whoops, my bad, the index is actually OK, it's only the table-of-contents that's messed up.

      Sorry 'bout that.

      I still find http://www.python.org/doc [python.org] a better source of information.
    • other useful books:

      The Quick Python Book by Harms and McDonald
      This one covers a quite older version of python (1.5), but is a good tutorial nonetheless.
      Programming Python by Mark Lutz
      A very good book to see python in action.
      Python Standard Library by Fredrik Lundh
      A very good reference book for some things not covered by Python Essentials (ex htmllib)

      However, I would greatly avoid the Python Pocket Reference (also by Lutz) just because it doesn't have an index to modules...
    • I haven't yet looked at Python in a Nutshell, but Python Essential Reference [amazon.com] is my current Bible. I have never come across a more complete index. I own a bunch of Python language books, and I constantly return to Essential Reference. The only thing that I go to Programming Python [amazon.com] for is Tkinter stuff.

      One of the hardest things for Python authors to deal with is the constant evolution of the language. For example, the move from the string module to string object methods was a huge change and "Programming
  • Pythonic? (Score:2, Funny)

    by iworm (132527)
    Dear Reviewer, what's with this constant use of "Pythonic"?

    Would you wish to repeatedly read "Ceeish", "Fortranish", "Javanical", "Perlectic", etc? Mildly witty the first time, bleedin' annoying the fourth or fifth.

    Thank you.
  • Oh, well. (Score:5, Insightful)

    by rice_burners_suck (243660) on Wednesday April 16, 2003 @11:57AM (#5744197)

    636 PAGES.

    This review is quite positive. I'm sure some faults could be found in this book, but suppose for a moment that I take your word for it and assume that this book is perfect. In such a case, I wish that more programming books would be published like this one.

    I don't currently use Python in my work but I increasingly find that language reference and instruction books are either too darn complicated or too darn simple. You either have to be a complete idiot, who has never seen a computer, let alone programmed one, in order to read a book written for such idiots; or you have to be an unnaturally staid and steadfast compiler writer to understand the endless maze of technical details published into thick volumes intended for such stalwart masters.

    I find that some of the slimmer, older volumes on C are written in a very readable fashion that require neither of the above virtues. However, newer books make the subject too complicated. Books on C++ are beyond help. Sometimes I wonder if our programming languages are much too complicated and perhaps should be reduced to a small number of basic elements, such elements being combined through the use of multiple languages in order to accomplish a specified goal. On the other hand, doing so will make development much too difficult. As such, it is up to the authors of explanatory volumes to make available a desired level of detail while keeping the material readable. It is this balance that I seek in programming books. Until then, well, I'll have to keep writing small "test" programs to probe the features of the language and of the compiler.

    Oh yeah... and of course, I would like these volumes to be of allowable length for reading in an afternoon or so. 636 pages sounds like a good length.

    • Re:Oh, well. (Score:3, Insightful)

      by Blaine Hilton (626259)
      I think this is a good point. IT seems for every language you have your "newbie" book, and then you have your advanced book. There is no standard middle of the road one usually. I believe this is in large part due to the speed of the industry. Languages that have been around longer such as C, C++, and perl seem to have many more books then Python or PHP.

    • Until then, well, I'll have to keep writing small "test" programs to probe the features of the language and of the compiler.

      Bingo! You have hit on a major problem that I never see in essays on "why software sucks". When documentation is missing, wrong, vague, or incomplete then the best you can do is test things until you get a "works for me" (the general "you", not specifically the poster of the parent).

      So what's the problem? If you use trial-and-error to get something working, you can't tell whether

      • Of course, there is always the theory that "If it was hard to write, it should be hard to understand. [ic.ac.uk]"

        Language documentation should effectively explain the language to a real human (not a staid and steadfast compiler writer) who actually needs to use the language (and not someone who doesn't know how to use a mouse but feels they should learn to program). Library documentation, on the other hand, should be extremely detailed. First, a description of the theory behind the library's design should be provided,

  • by liquidsin (398151) on Wednesday April 16, 2003 @12:00PM (#5744213) Homepage
    Your python shouldn't be in the nutshell, it should be hanging comfortably in front of it. You may want to have a doctor check that out...

  • by hfastedge (542013) on Wednesday April 16, 2003 @12:00PM (#5744217) Homepage Journal
    Slashdot accepted something from python by me, and here it is again as I think its relevant. Python is just great :-)

    http://slashdot.org/articles/03/03/11/1817203.shtm l [slashdot.org]

    hfastedge [wikipedia.org] writes "Ok, now that 2 perl conferences have been mentioned, I've been brought over the edge. Python [python.org] is a language that is just as old, and arguably [www.amk.ca] better from: most importantly a uniform standard of readability (enforced by using whitespace [wikipedia.org] to delimit blocks (instead of {}), by avoiding overuse of cryptic symbols, and by a culture [python.org] that strives to keep innovations as "pythonic"), and a rich [python.org] development [python.net] community. Anyway, normally, there are Python events [python.org]

    in Europe, and a trail at O'Reilly's OSCON. But now, there is a far
    cheaper event taking place on March 24-28 in Washington DC: http://python.org/pycon/ [python.org].



    Examples of Python in action: , 1 [google.com], 2 [pythonware.com], 3 [oreillynet.com], 4 [intelligen...rprise.com], 5 [scipy.com], 6 [onlamp.com], 7 [pygame.org]"

  • by josephgrossberg (67732) on Wednesday April 16, 2003 @12:02PM (#5744231) Homepage Journal
    Seriously, why would anyone want to pay $35 for something that isn't much different from the online documentation?

    Learning Python was great, as was the Python Cookbook. They had something to offer beyond a documentation of Python features (an explanation and an exploration of them, respectively).

    Unless you have no internet connection or just greatly prefer dead trees, I can't see why you'd get any of the "brown" books.

    Has anyone here been pleased with O'Reilly & Associates' ever-present "... in a Nutshell" books? I'd be curious to hear what the appeal is.
    • I'd agree with the other guy that said it depends on the subject.

      I have a Java Nutshell book and a Linux Nutshell book. The Java Nutshell is next to useless since Sun's Java Documentation is superb and is easier to navigate. The Linux Nutshell book is extremely handy since I'm not aware of any comparable online reference and there are so many obscure commands with random syntax to wade through.

      So, you would probably find subjects with useful Nutshell books lack a strong, easy to navigate online referenc
    • I didn't much care for the Java in a Nutshell but did like the companion volume, Java Examples in a Nutshell. It's the closest that I could find to a "Java Cookbook"-- every other Java book just rehashes the documentation, assuming that if your problem were a common problem, it would be covered in the stock API already.

      • The first Java in a Nutshell book was excellent. By the second edition the language specs had become so large that the examples had to be split out into a second book. Both books suffered tremendously as a consequence. I have no idea what the current status is, but the approach is wrong once a language becomes grossly swollen.

        The correct approach (ex cathedra):
        1) Examples need to be combined with the language, not in a separate book.
        2) The book should be about 400-500 pages. If it's longer, you need to
    • Having had to do some VB6 programming (thank God it's behind me now), I found the VB In A Nutshell Book indispensible. The author gave an example with each entry, explained quirks (VB has quirks? go figure) each feature had, and tied it to related features.

      So it really depends on the author and the subject. I don't own Perl in a Nutshell, or Java in a Nutshell though I've programmed in both of those languages, but I bought SQL in a Nutshell because it's well-written, concise, and I have my documentation f

  • No... (Score:2, Funny)

    by The Mainframe (573877)
    No, this is python in a nutshell:
    "Help! I'm in a nutshell! How did I get in this awfully big nutshell? What kind of nut has a shell like this?"
  • by Pizaz (594643) on Wednesday April 16, 2003 @12:13PM (#5744299)
    Deer Slashdott.com, I've decided to right a book witch will bee very relevant to your readership (i.e geeks and nerds). Although i've yet too decide on the subject material, im very much looking forward to getting rich quick. Eventually, win I finish my book, i'd like too submit a glowing pseudo review to slashdott which contains a link to an online bookstore so that geeks and nerds and can start making me rich right away. Do these sorts of advertisements cost very much? I'm taking a cours in righting and I'll be able to start on the book real soon after I pass these lessons. Thank you. Looking forward to hearing from you so that I can start on the path to richdom.
  • by avdi (66548) on Wednesday April 16, 2003 @12:23PM (#5744363) Homepage
    By far the best programmer's introduction to Python (in fact, one of the best programmer's intros to any language) I've ever read is Mark Pilgrim [diveintomark.org]'s Dive Into Python [diveintopython.org], a free online book.
  • by mzs (595629) on Wednesday April 16, 2003 @12:26PM (#5744381)
    The book I both used to learn python and continue to go back to as a very useful, detailed, and fairly complete reference is "Python Essential Reference" by the creator of SWIG David Beazley. (If you ever wanted to mix C, java, python, perl, tcl go to http://www.swig.org/ sometime.) There is a newer second edition out now but the orignial was laid out as a short tutorial chapter to get started in python, then several short chapters about language details (lexical matters, types, operators, control flow, functions, classes, modules, and I/O), and the typical chaper about installation and site issues. This first section is less than 90 pages, fantastic for people already familiar with programming that want to quickly learn the syntax of python so they can get immediately started with python coding.

    Then there is Appendix A which gives a short description of all built in functions and exceptions followed by concise descriptions of most of the standard python modules circa 1.5.2 (the newer edition is probably 2.0-ish) that are detailed enough to use as reference. Appendix A also has short examples and detailed explanations with background information where it is beneficial in the descriptions. The module reference is divided into topical sections such as string modules, networking modules, and threading modules and modules with related or complimentary functionality are cross referenced.

    Finally there is a short Appendix B that explains how easy it is to extend python with C modules and even a bit of how to embed the python interpretter into your own programs and libraries!

    Most importantly the book is only 274 pages and has a very useful index when you want to use it as a reference. Together with the online documentation at http://www.python.org/doc/ this book is invaluable to me.
  • by Anonymous Coward
    Cameron Laird: Book review: Python in a Nutshell [unixreview.com] "Cameron Laird reviews Alex Martelli's 'Python in a Nutshell' for UnixReview.com. Experienced, erudite author. Compelling topic. Proven format. What happens when you combine them? It depends. In book publishing, as with rock-and-roll bands and athletic teams, there are plenty of cases where apparent 'all-star' combinations have turned out badly. The fate of 'Python in a Nutshell' is happier, though. If you want to learn about Python, and can choose only one
  • by Anonymous Coward
    Here's how I see the language.

    Combines the flexibility of syntax of C with the efficiency of Javascript. Python can't realistically support Lisp-style macros, doesn't support true closures, and many other things of Goodness that make Lisp languages so good for rapid coding. On the other hand, Python's dynamicism makes it very very slow. It's bad enough that the Python zealots [twistedmatrix.com] apparently don't know how to program Java -- as minor corrections to their broken test code result in Java code that just stomp

    • > Python can't realistically support Lisp-style macros, doesn't support true closures, and many
      > other things of Goodness that make Lisp languages so good for rapid coding.

      Strange that Python doesn't support Fortran type line numbers or BASIC type OPEN statements either. If you want to use Lisp, use Lisp. Python is its own animal.

      > Python is slow. So we have a slow language. So what?

      Exactly. So what. The speed of the interpreter is usually not the bottle-neck in most app domains. If it is, use
    • But Python's missing many of the goodies that make slow languages great. Macros.

      Not having macros was a deliberate design decision. One of Python's key stengths is easy readability and adding the ability to add/modify language contructs might compromise this.

      A good, scientifically-oriented numerical facility.

      What facilities are you looking for, in particular? Python has a double-precision floating point type, unbounded integers and complex numbers as part of the core language. Are you looking for so
  • Dive Into Python (Score:2, Redundant)

    by L3WKW4RM (228924)

    I've got to recommend Dive Into Python [diveintopython.org] as a great, free, online Python book.

    (PS. I own the dead-tree version of Python in a Nutshell, I think the above is nice to use as a while-programminng guide)

  • by Paul Komarek (794) <komarek.paul@gmail.com> on Wednesday April 16, 2003 @02:38PM (#5745376) Homepage
    I cannot agree with the reviewer that M. Lutz's O'Reilly "Python" book is good. I disliked this book nearly all the way through. It jumped around too much, used too many words, and had insufficient detail on more advanced topics. Given that the book is about three inches thick (from memory -- I gave away my copy), there's enough room for details on everything.

    I concur with other posters that the "Essential Reference" (white and red from New Riders, written by D. Beazley who did SWIG) is an awesome book. It is concise, making it a good reference. I wouldn't think it was a good book for those who have never programmed. If you have some programming experience, though, I expect you'll appreciate this book.

    The "Quick Python" book from Manning is nice, too. This was my wife's preferred book for learning Python. I've looked through it a bit, and it seems decently concise but with more explanation than "Essential Reference". I used its section on extending Python through C, and found it very useful. That section didn't have everything bit of reference that I needed for conversion specifiers, but their examples were dead-on what I needed to get started.

    I recently finished reading through "How to Think Like a Computer Scientist: Learning With Python" from Green Tea Press. This book is not a complete reference or guide for Python, nor will it be particularly 'useful' for people who have taken university-level programming and data structures classes. However, it seems to be an AWESOME book for people who don't yet program, or whose only experience is web programming or VB or Perl programming (I'm not saying those things are bad, but very often they don't encourage reasonable programming discipline and methodology). I write "it seems" only because I'm not a beginner or an instructor for intro to programming courses.

    This book ("How to Think...") is aimed at classroom use, so it doesn't include info about installing Python or starting the Python interpreter under Windows, etc. It does preach solid computer science. Parts of their approach seemed a bit unusual to me, compared to my more classical training, but after a few gripes I always was forced to conclude that their approach was valid and as concise and clear as it could be. The authors are aware of the book being used in high schools and community colleges. I expect that mature students, or any adult intrested in learning proper programming, would benefit from starting with this book.

    -Paul Komarek
    • I cannot agree with the reviewer that M. Lutz's O'Reilly "Python" book is good. I disliked this book nearly all the way through. It jumped around too much, used too many words, and had insufficient detail on more advanced topics. Given that the book is about three inches thick (from memory -- I gave away my copy), there's enough room for details on everything.


      Mark Lutz actually has two noteworthy Python books, "Programming Python" and "Learning Python."
      "Programming Python" would be the thick book you re
    • Great book. I have read several of the OReilly titles. They are great to understand how historically some features got into the language, etc. They also greatly contributed to the Python advocacy. But in a way, it's also their downfall: they tend to be dated.
      The only Python book I read now is the New Riders title. I can find just about anything in it as fast as I can search Google. OK, *almost* as fast.
    • Another book for adults...

      Learning Python is getting rather dated (version 1.5 or sumthin). As an alternate, I can recommend Peachpit's Visual Quickstart Guide Python by Chris Fehily. It's a thorough, well designed introduction for people who like to learn while doing. Most of the examples are done at the interactive prompt.

      The chapters are well laid out and progress rationally: the separate chapters on Numbers, Strings, Lists, and Dictionaries are followed by Control Statements. Eventually Modules, Clas
  • I have never gotten around this. I probably never will get around this.

    With braces, as in perl or C, I can bounce on the % key and find the ends of a block unequivocally. I can cut and paste from one editor to another, and it still works. I can change tabstops and everything still works.
    • The % feature depends on your editor. If your editor is decent, you can jump up/down Python blocks as well, or at least script the editor to be able to.
      As for tabstops - that's indeed a problem with Python, one a Python programmer should be aware of.
      However, once the Python programmer is aware of this problem, its not really serious, because rarely will indentation problems result in anything other than IndentationError raised, and you can simply search-replace all tabs to 4 or 8 spaces, or vice versa.

      The

"Catch a wave and you're sitting on top of the world." - The Beach Boys

Working...