Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
Books Media Programming Book Reviews Technology

Dive Into Python 309

Posted by timothy
from the sploosh dept.
AccordionGuy writes "If you've ever spent an afternoon in the "Computers" section of a bookstore going through the programming language books, you've probably noticed that most of them seem to exist only to boost a publishing company's fortunes by capitalizing on the hot new programming language of the moment. These books -- essentially glorified bookends -- seem to follow the same format, cover the same subjects and aside from the tiny flourishes that are part of each author's particular writing style, are indistinguishable from each other. Reading them, one gets the feeling that its primary purpose is to allow the author to make some payments on a car or mortgage. I have a few of these books and they're gathering dust on the bookshelf farthest away from my desk." For deVilla's review of Dive Into Python, a book that inhabits a completely different category, read on below.
Dive Into Python
author Mark Pilgrim
pages 432
publisher Apress
rating 9
reviewer Joey deVilla
ISBN 1590593561
summary The "desert island" Python book

However, from time to time, you can find a programming language book that stands apart. You can tell from the way the author writes, the topics s/he covers, the unique presentation style and insight that s/he brings that the book is a labor of love. These books enjoy placement on the shelf closest to my desk -- that is, if they're not propped open beside my computer. Dive Into Python is such a book.

One thing that sets Dive Into Python apart from many other programming language books is that its author, Mark Pilgrim, didn't originally plan to make any money from it. As we often say in Open Source circles, he simply had an itch and decided to scratch it. Mark explains this in a story on his weblog in the form of a dialog between him and his manager after showing him a rough 20-page draft:

Manager: "This is really good. You could probably make some money off this someday."
Mark: "Maybe, but I'm not going to. I'm giving it away for free."
Manager: "Why would you do that?"
Mark: "Because this is the way I want the world to work."
Manager: "But the world doesn't work that way."
Mark: "Mine does."

First released in late October 2000 and published in online and downloadable forms under the GNU Free Documentation License, Dive Into Python had grown in fits and starts until 2003, when Mark declared the project closed. Even as an unfinished work, it was held in such high regard by the Python community that developers consistently recommended it; it was also included with ActiveState's Python and FreeBSD's ports distributions. When Mark announced that Apress had decided to pay him to finish the book and publish it, it became the most-anticipated book on Python ever. Even better, Apress has been gracious enough to allow Mark's world to work way it always has: Dive Into Python is still available for free download and is still under the GNU FDL.

What's in Dive Into Python

Many programming language books follow what I like to call the "Computer Science 101 Format", with the first few chapters devoted to covering basic concepts that any moderately experienced programmer already knows. Whenever I leaf through such a book and encounter a chapter that tries to reintroduce me to data types, looping or branching, I feel cheated; I'm essentially paying for a big chunk of book that I'll never read. If you've ever been annoyed by such filler, you'll find Dive Into Python a refreshing change. Rather than wasting time and trees devoting whole chapters to rehashing Computer Science 101, Mark chose to build each chapter after the first around a program that illustrates a number of Python features and programming techniques.

The programs upon which Dive Into Python's chapters are based strike a carefully-maintained balance. They are rich enough to illustrate a number of points and be the basis for some "real world" code, yet small enough to be comprehensible tutorials. For example, chapters 2 and 3 are based on "Your First Python Program", which is a mere six lines of code. However, in those six lines, you are introduced to function declarations, documentation strings, objects and their attributes, importing modules, Python's indentation rules, the "if __name__" idiom, dictionaries, lists, tuples, string formatting and list comprehensions. Within the first hundred pages, a point where many books are re-acquainting you with the "else" keyword, Dive Into Python covers the aforementioned topics as well as Python's reflection capabilities, list filtering, the "and-or trick", lambda functions, OOP and exception handling, all with enough thoroughness to be useful. After reading Dive Into Python, you may have trouble reading other programming language books because they'll seem glacially slow and fluff-laden in comparison.

For the first two-thirds of the book, Mark continues with this approach, presenting a program and then analyzing it to see what makes it tick, teaching Python and oftentimes a programming technique along the way. Each program covers useful tasks that you're likely to run into while programming and does so in an interesting way. At the same time, concepts are introduced in a way that makes sense. For instance, chapter 4 covers two topics that mesh together quite well -- exceptions and file handling -- and it does this by exploring an interesting application: a program that displays the ID3 tag information about each file in your MP3 collection. Later chapters explore regular expressions, HTML and XML processing and Web services. By the time you've finished the first two-thirds of Dive Into Python, you'll have been introduced to enough Python to start writing a wide array of "real world" applications. The book might have benefited from having a chapter covering database access, a task that's at least as common or as useful as accessing Web services, but that's a minor complaint.

While the first two-thirds of the book concerns itself with helping the reader become a Python programmer, the final third is about elevating Python programmers above mere competence. It covers useful topics (albeit rarely-covered in language books) such as refactoring and performance optimization as well as ones that may be new to even some experienced programmers: unit testing, functional programming and dynamic functions. Each chapter in this section is still based on an example program, but rather than analyzing a completed program, its evolution is traced. Although you can get by as a Python programmer without ever reading the material in this section, you'll be a much better one for having done so.

In keeping with the spirit of Python, Mark writes the chapters to present the material as completely and clearly as possible without extra clutter. If there's any additional material that doesn't apply directly to what he's trying to explain, he provides references or links to that material rather than attempting to "fatten up" the book.

The book's long gestation period, assisted by years of reader feedback and James Cox's editing has paid off. It doesn't have the rushed feel that many language-of-the-moment books have (especially the ones written by an army of authors, each one taking a chapter). As far as I know, there isn't any of the sloppiness that pervades many programming books these days, save one instance of the popular typo "teh" (and really, what truly 1337 book doesn't have one of these?).

Mark is aware that Python is likely not to be the reader's first programming language; it's more likely to be some descendant of ALGOL (or more precisely, a language that borrows heavily from either C or BASIC). He also knows that many programmers tend to misapply techniques from the languages with which they're familiar to the language they're learning. With these in mind, he's taken great care to introduce Python idioms as soon as possible. If you follow his advice, you'll be writing "real" Python and taking advantage of what the language has to offer rather than just writing Python-flavored version of whatever programming language you're most comfortable with.

Dive Into Python's Audience

The "user level" specified on the back cover of this book says "Beginner - Intermediate", which I feel is a little misleading. As I mentioned earlier, the book takes great care not to rehash topics with which programmers with some experience are already familiar and is written with the assumption that the reader is proficient in at least one object-oriented programming language. I think many programming novices would be overwhelmed with the speed with which Python features are introduced.

Experienced programmers, whether they are new to Python or are fluent with the language will benefit the most from the book. One programmer I know works with Python daily and and even submitted a patch to wxPython; even he said that Dive Into Python showed him things about Python that he never knew. If you're tired of books aimed at "Introduction to Computer Science" students, you're going to love this book. This doesn't mean that people who don't normally program can't benefit from the book: Joi Ito, who is a tech entrepreneur and not a programmer, learned enough from Dive Into Python to put together jibot, a bot for the IRC channel that bears his name. If you're new to programming, you might want to make Dive Into Python your second book or supplement it with an introductory text such as Apress' own Practical Python, O'Reilly's Learning Python or the free online book How To Think Like a Computer Scientist (the Python edition).

Conclusion

Dive Into Python may be one of the thinnest programming language books on my shelf, but it's also one of the best. Whether you're an experienced programmer looking to get into Python or grizzled Python veteran who remembers the days when you had to import the string module, Dive Into Python is your "desert island" Python book. If you're new to programming but have heard all the wonderful things about Python, make sure that this is the second programming book you read. My congratulations to Mark Pilgrim on an excellent book and authorial debut!

(Remember, you don't have to just listen to my effusive praise. Dive Into Python is available for free at diveintopython.org. Read it for yourself and if you like it, vote with your dollar!)


You can purchase Dive Into Python 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.

Dive Into Python

Comments Filter:
  • by Anonymous Coward on Wednesday September 08, 2004 @02:01PM (#10192892)
    Dive Into Mark [diveintomark.com]. Lots of interesting/useful stuff.
  • Broken Link (Score:5, Informative)

    by keiferb (267153) on Wednesday September 08, 2004 @02:06PM (#10192968) Homepage
    Here's a good link to diveintopython.org [diveintopython.org]. The one at the end of the review is horked.
  • by Neil Blender (555885) <neilblender@gmail.com> on Wednesday September 08, 2004 @02:06PM (#10192974)
    With perl, you can learn all that with 6 characters.
  • Finally! (Score:5, Interesting)

    by bblazer (757395) * on Wednesday September 08, 2004 @02:08PM (#10192995) Homepage Journal
    I have been waiting a long time ti find a book like this. It is a breath if fresh air. Similar (as far as fresh air goes, not writing style) to the Head First series. While the Oreilly 'animal' books take up most of my shelf space, this one will find a place there too.
  • Great Book (Score:5, Interesting)

    by wackysootroom (243310) on Wednesday September 08, 2004 @02:08PM (#10193003)
    It's the first thing I recommend to read after the official python tutorial [python.org] to my co-workers who are just starting to learn python.

    This book, Python in a nutshell, and the online python library reference are the 3 tools that I always recommend for python newbies
  • by Donny Smith (567043) on Wednesday September 08, 2004 @02:16PM (#10193107)
    If writing a book like that could get me $60K a year kind of job, I'd write one for free too.
    (I hope the author makes enough money - I just want to point out a possible reason for doing that kind of thing).

    From the article I noticed one interesting thing - his world didn't quite work out until that company chipped in some money for him to finish the thing.
    The same is with music and software - if it weren't for companies and/or sponsors....

    Just in case the site crashes, you should be able to get the book via eMule( "diveintopython" the current version is 5.4.)
    • by janbjurstrom (652025) <.inoneear. .at. .gmail.com.> on Wednesday September 08, 2004 @03:11PM (#10193839)
      I guess you could see it that way. But I read his weblog semi-often, and from what I've learned, Mark did a sort of 'project house-cleaning' a while back (sometime after his marriage?). He talked about wanting to use his time in the most meaningful way, and therefore listed a few time-consuming things he would

      a) stop doing altogether
      b) keep maintaining but not work actively on
      c) spend his 'new-found' time on.

      I believe the Diveintopython project was put in group a). So IIRC this would mean that APress gave him an offer to finish it after he chose to abandon the project himself.

      I could be mistaken but I'm too tired to check his site now.. You do it ;).
    • by Jason Earl (1894) on Wednesday September 08, 2004 @03:17PM (#10193925) Homepage Journal

      Dive into Python has always been a good book for some time now. The difference is that now it is available in a dead tree version, and it has had some professional editting.

      His world worked out just fine. In fact, his free edition was good enough that he's getting paid to make a dead tree version while still giving away the electronic version.

      It just goes to show that there is money to be made in this kind of stuff. Not huge piles of money probably, but enough to make it worth your while.

    • by nessus42 (230320) <doug@al u m . mit.edu> on Wednesday September 08, 2004 @03:21PM (#10193977) Homepage Journal
      From the article I noticed one interesting thing - his world didn't quite work out until that company chipped in some money for him to finish the thing.
      So? His world still worked out the way that he wanted it to. He still gives out the book for free if you don't want to pay for it. Proponents of free information have never said that the creators of the information shouldn't also be able to make money from it.

      |>oug


    • If writing a book like that could get me $60K a year kind of job, I'd write one for free too.
      (I hope the author makes enough money - I just want to point out a possible reason for doing that kind of thing).

      I'd bet the money making part is one level of indirection from writing the book.

      That is, when you put out a resume looking for consulting jobs, etc. being able to list yourself as the author of a widely-recognized and lauded work is helpful.

  • strange that this article should pop up today when just last night, i was digging through the local barnes & nobles looking for a good python book and went home with nothing more than another work of fiction.

    i've been meaning to get further into computer programming than the basic knowledge i already have, and this book seems worthy of a purchase. i have suffered through quite a few "intro" books that do little more than teach how to code math equations and silly text manipulations.

    what i am really in
    • by bhsurfer (539137) <bhsurfer@@@gmail...com> on Wednesday September 08, 2004 @02:54PM (#10193614)
      Have you read The Practice of Programming [amazon.com] by Brian Kernighan & Rob Pike? I thought it was a pretty good "why-to" sort of book that didn't spoon feed you anything, plus it gives examples/assignments in multiple languages so you can see the differences between them. If you haven't read this one, check it out. They probably have it at the library if you don't want to read it, but I'm glad I own a copy.
    • by claytongulick (725397) on Wednesday September 08, 2004 @03:27PM (#10194050) Homepage
      The "Why-to" question is the core of what separates good programmers from bad.

      Inadvertantly, you question strikes to the core of modern IT, it is not language specific, but it is the root driving force behind all "geeks".

      For too many people, the "Why-to" is "because I heard you can make lots of money as a programmer". To answer this demand, colleges and universities churn out rank and file incompetent and ambivalent programmers, weilding their Microsoft inspired toolchest of Visual Basic 6 or MS Access, they flood the resume pool, and pollute the code base with their lazy half-hearted attempts at development, causing project failures and frustration on a massive scale and dramtically increasing the costs of corporate IT.

      These are the type of programmers who react with anger and fear when anyone mentions exploring different languages or technology. Who, when confronted with a problem or issue they don't understand are willing to shrug and say "I don't know" and pass the problem off to the true "geek" on the team.

      On the other hand, you have the type of coder to which the "Why-to" question is like breathing... to whom coding grants god-like powers of creation, who is willing to stay up late solving obscure problems just for the rush of satisfaction when s/he gets the answer.

      To this type of coder, the question is not so much "Why-to" but more, "How could I not?". Coding is not a job, it is a system of thought, the logical structuring of the chaotic real-world into discrete lines of code.

      To this type of programmer, there is nothing more exhilarating than a new project, a blank file, a clean slate, from which they can craft the perfect solution. Starting from scratch and creating from nothing is the ultimate expression of their intellect, and they judge themselves critically by the result.

      This is a quality that can not be taught in a univeristy, or measured by a multiple choice exam. These are the "basement geeks" who clutter their shelves with gadgets and obscure books.

      They may have started on the IRC with the classic question "How do I make a game?", or as a sysop of a dial-up BBS who needed to add functionality.

      The point is, for the true coder, the "Why-to" question was answered BEFORE the language question... they had some sort of need that could only be solved by learning to code... and after that they were hooked. They constantly evaluate new languages and more effecient/elegant methods of solving their problems.

      There is no book that will make you _want_ to code, first you want to code _then_ you buy the book.

      Asking "Why should I program?" is similar to picking up a shovel and saying "Why should I dig?". Unless you have a need, there is no point, and you will never understand why all those ditch-diggers keep debating the finer points of different shovels. You are out of context. For you, the answer is "You shouldn't".

      That is, until you need a ditch.
  • My 2 cents (Score:5, Insightful)

    by KillaKen187 (794540) on Wednesday September 08, 2004 @02:19PM (#10193153) Homepage
    Python is great very robust, easy to use, and capable to do a lot of things quickly. I also know that Mark is a great guy. I have sent him emails on trouble I have had on things and he has given great responses to them. Very upstanding guy. All blessings to Mark Pilgrim and his contribution to OSS with Python.
  • by bludstone (103539) on Wednesday September 08, 2004 @02:19PM (#10193158)
    ...and got covered in spam. ...bloody vikings
  • by powerlinekid (442532) on Wednesday September 08, 2004 @02:20PM (#10193178)
    A few years back I needed to develop a program to download all of UserFriendly's archives (ok need is a strong word but thats not important). At the time I was familiar with the normal languages; java, C, C++, etc. I had heard about Python and figured this was something I could use to learn it.

    I was blown away. Having never touched the language within a couple of hours of going through the online documents I had picked up enough to write the full script. Once that was done I didn't want to stop. I found Python to be an absolute wonderful language that made programming fun again. Since then I've written my fair share of Python apps to do nearly everything. Infact anytime I need a program that I can't quickly find or isn't out of it's realm, it gives me an excuse to use Python. A lot of the time I lookup a way to do something and sit there smiling to myself going "now thats freaking cool".

    I haven't read this book, but from my experience Python is an awesome language. I'm sure the Perl people feel the same way about their language. To me Python feels clean, flexible and productive. Most importantly its fun.
    • A few years back I needed to develop a program to download all of UserFriendly's archives

      You're either a masochist, or this was some form of cruel and unusual punishment. Perhaps you could enlighten us as to why someone would willingly subject himself to UF's brand of mind-numbing "art" (requires quotes because I can't call it real art with a straight face) and "humor" (same reason for the quotes).

    • Yep, the above poster was one of the people who get me to look into python. I love it now. I hate when I have to go back and look at perl code that I or others have written now.

    • by Lodragandraoidh (639696) on Wednesday September 08, 2004 @09:35PM (#10197260) Journal
      My language experience going back 24 years:

      Basic, Fortran, Assembly (Intel and Sparc), Pascal, C, C++, Java, Lisp, shell(sh,awk,sed), Perl, and most recently Python. (roughly in that order; I saw some COBOL code once when a young programmer, but was immediately repulsed - thank heavens)

      I actively use Perl and Python myself for everything now for several reasons:

      1. All of the machines at my job (800+) are all preloaded with Perl - so I have to use it for automation (better than shell scripts particularly for mission critical one-off applications that have to be fault tolerant but deployed at the whim of our marketing and operations staff). If I didn't have to maintain Python myself on all of those machines, I would port everything over to Python in a heartbeat. However it took me 2 years to get management to agree to loading Perl in the first place - and there is no reason to incur the costs associated with validating a new scripting language for use in our production environment. So I live with it - and keep the footprint small.

      2. For all other tasks - I use python.

      Some neat things fall out of python [python.org] that even as a neophyte I can appreciate:

      a) clean syntax (if I only had all the time spent finding dangling semicolons in perl, I could take a sabbatical)

      b) full featured web development tool (Zope [zope.org] - provides a framework for developing and hosting full service applications - designed to make building products to run under Zope easy - seperates the presentation from the logic using ZPT cascading style sheets and DTML for presentation, and python for the program logic [unless you are masochistic enough to depend upon DTML alone] - has a built-in database for managing Zope objects - and built-in httpd and ftpd servers - which can be further frontended using Apache as desired - can communicate with other databases [oracle, ODBC, postgreSQL, etc... many database plugins available] - has a large library of predeveloped products [modules for you perlmongers] that you can load and be up and running, or modify to your heart's content - and did I mention that its GPL'd?)

      c) platform independent (just as with java and perl, python scripts can run without modification on many operating systems - keeping porting costs down to a bare minimum.

      d) built-in documentation functionality - not as full featured as Perl's perldoc - but I might not have found the right product yet to do that (ideas anyone? or, is this a python project waiting for me to jump on - perhaps something that ouputs XML?)

      The only drawbacks (and I use this term with trepidation - because they can seem positively refreshing after 10 years with perl) that I can see are:

      A. Does not have the sheer amount of user contributed products (modules) when compared to CPAN^ [cpan.org]. Of course I wouldn't judge the quality of my carreer based on the weight of all of my program printouts either. Quantity does not equate to quality.

      B. Slower than Perl and Java. Again, something I can throw hardware at to rectify. Squid goes along way to making web pages generate faster too - so you can ameliorate some of the problems without having to kill yourself.

      C. Sometimes it takes longer to find resources online than with other languages because of the difference in popularity. However, the time spent needing to refer to reference material for Perl and Java is many times larger than the time spent doing the same with Python.

      D. Because of my long experience with Perl, I find myself immediately jumping to a predetermined algorithm/function that is implemented differently in Python and thus create syntax errors in my code. This last is really a personal problem that time will erase.

      My whole programming paradigm has changed. The advent
  • Python: The Movie (Score:5, Informative)

    by PissingInTheWind (573929) on Wednesday September 08, 2004 @02:20PM (#10193179)
    For all of you who still haven't seen it, I strongly recommend this 'propaganda' gem from the Python community:

    Video: Introducing Python [ibiblio.org]

    Features GvR, ESR, etc.

    It's so bad it hurts. You'll want to show it to all your friends.
  • I've been using Python for years and I like to read all the books I can get my hands on. Yeah I'm one of those Python Zealots.

    This book is quite good, although the PDF has odd little gray icond behind some of the text for some reason. It doesn't bother me really but I'm not sure what their for.

    The book does have some great chapters and some not so hot ones but it's probably not the best read if you don't already have some Pygramming (that's Python Programming) experiance.

    Lots of fun and by far one of the
    • by cryptochrome (303529) on Wednesday September 08, 2004 @03:40PM (#10194192) Journal
      I've been programming pretty much exclusively in python lately - but as my programs have become more advanced the downsides are becoming more obvious. I ended up writing a python extension in C (painful when you've been programming in python). Specifically, you can't compile python - and interpreted it's just too slow for anything computationally expensive. Also you have to load the interpreter, (or embed w/extra modules) it's slow and uses more memory than it should.

      PyObjC is a start, but the little differences in how things are implemented between Python and Objective C makes using it a bit difficult to learn. Plus it's mac-only. Pyrex looks interesting but I've yet to try it. PyPy seems to have been in development forever.

      For starters, I think the distutils module needs an option to produce a package/binary that is runnable on any similar machine whether python is installed or not.

      Python is amenable to a variety of programming styles, is very readable, has well developed libraries, and is quick to write. But I've found myself wanting more than it can deliver, in terms of raw speed and number-crunching power, and even occasionally the need for typing and assignment by reference. I hope they find some way to deliver it someday, or make a language that retains the ease and efficiency of python but is also compilable.

      • There is a python compiler for Win32.. i dont have the name handy but a quick search on Guido's site should bring it up for you..
        • Re:Python Compiler (Score:3, Informative)

          by cryptochrome (303529)
          there's py2exe... but that's just an executable with the python interpreter and all necessary modules and code included, IIRC.
          • py2exe is exactly what you asked for. There's similiar packagers for both Linux and OS X (Py_Freeze for linux, I'm not sure what the name of the OS X one is).

            As for writing C extension modules, take a look at Weave.

      • I ended up writing a python extension in C (painful when you've been programming in python).

        Bridging between languages with totally different type systems is usually tedious. Try SWIG, or PyRex, or Boost Python.

        Specifically, you can't compile python - and interpreted it's just too slow for anything computationally expensive.

        Are you trolling or just ignorant? Sorry for being harsh but this statement is wrong, misleading, and overly broad all at the same time.

        First, Python is NOT interpreted (y
        • Try SWIG, or PyRex, or Boost Python
          I started with SWIG, and eventually decided it was easier to just write my one function myself instead of trying to learn all the ins and outs of swig. I didn't discover pyrex 'til later, and haven't really looked into boost.

          compiled to byte code and then executed in a VM
          Then I'd prefer that it not require a VM.
          If you think it's to slow because it's not native the same goes for Java and C#.
          Correct.
          to point out that saying "it's too slow" without qualification is an
  • by BuzzLY (267639) on Wednesday September 08, 2004 @02:23PM (#10193212) Homepage
    As an author of one of those "bookends," I'd have to assume that AccordianGuy has never written one. The money is certainly not a huge draw -- it's not enough to live on, for sure. I can't speak for all authors, but for me, it was an opportunity to do two things that I love - play with one of my favorite programming languages, and write. Perhaps it really is crap, but at least I enjoyed writing it!
  • by HungSquirrel (790165) on Wednesday September 08, 2004 @02:23PM (#10193213) Homepage
    The developer of gmailfs [jones.name] wrote it in Python. He claims it is his first jump into Python, and apperently he learns fast--two days from zero Python knowledge to a working prototype of gmailfs. Odds are decent that he learned from this book. If everything people are saying about Python is true, I might have to give it a go. I can already tell from Chapter 2 of this book that it's my kind of programming guide, so I shouldn't have any trouble.
    • by Anonymous Coward
      That's the weirdest endorsement I've ever seen for a book. "This guy, who's not remarkably good at X, but claims to have picked it up quickly, may or may not have learned X from this book. However, I'm assuming that he did! What a great book!"
    • by gr8_phk (621180)
      I finally decided to try Python about a week ago. My goal was to scrape some information from a web page for easy/compact display. Pulling the raw HTML from a given URL is simple with the urllib. Python string handling makes parsing text fun and easy. The interactive mode actually allows you to define functions on the fly and try them without editing/saving/compiling files. And lastly, the thing I feared most... The "indentation matters" concept is fantastic.

      Using Tkinter for a GUI is not as simple as I h

  • by Golthur (754920) on Wednesday September 08, 2004 @02:33PM (#10193335)

    I wasn't a Python Zealot(tm) until I tried it... in fact, just the opposite.

    When I heard about the whitespace-is-significant, I had nightmarish flashbacks of MVS JCL (thoughts of which still cause me to twitch uncontrollably). As such, I refused to even look at Python seriously for quite some time.

    However, that being said, once I actually did get over my (admitted) prejudice and gave it a serious test - it earned an official "WOW", something which few languages have ever done for me. Never mind that I was as productive while just learning Python as I am as an expert in any of the other languages I use regularly.

    Now, I'm an official convert. Python gives you all the tools you need, but never forces you to use the wrong one for the job.

    All I need to do now is find a shop that actually uses Python...


    • Interesting to hear this, because that is exactly my reaction to python.

      "Wow, sounds interesting but when you cut and paste chunks of don't you run the risk of shooting a hole in your foot and then somehow choking to death on the fountain of blood?"

      I'd be interested to know whether you still dislike the significant whitespace, or have somehow come to like it. And if so, why?

      • by nkh (750837)
        Indentation to create blocks is stupid when you begin to learn Python. And after a day or two you don't think about it anymore. The language is cool, and tabulation is just a detail when you've got OOP, regexpes...
      • by Anonymous Coward on Wednesday September 08, 2004 @03:15PM (#10193890)
        "Wow, sounds interesting but when you cut and paste chunks of don't you run the risk of shooting a hole in your foot and then somehow choking to death on the fountain of blood?"

        Get a smart text editor; one that can handle this. When I cut'n'paste Java code in Eclipse, for example, it makes all of thew whitespace perfect. Indenting and outdenting code should be no more than a few keystrokes. ("<<" or ">>" in vim's visual mode. ctrl-[ or ctrl-] in Eclipse. etc.)

        This is something I always did in other languages anyway, so Python's whitespace handling never bothered me. Improper whitespace drives me nuts (too hard to read), so a language that enforces proper whitespace is perfect to me.

        • by ashultz (141393) on Wednesday September 08, 2004 @03:56PM (#10194408)

          I tend to use emacs, which can handle indenting in any of twenty different ways, but anyway...

          My conceptual problem is that when I cut and paste a block of code to a new place, there is no acceptible default indent level - I might want to end the previous block and start a new one, or I might want to stick this under the if, or maybe it should go outside it, and there's no way for the editor to automatically know and do the right thing. I often in emacs select the whole file and tell it to correct the identation... which is impossible in python?
          • by Anonymous Coward
            Emacs python-mode makes adjusting indent levels for blocks trivial:

            Paste or select a block, C-> indents, C- outdents

            Don't bother selecting your whole file & re-indenting the whole thing.

            Note that with a brace/delimiter oriented language, you often have to manually insert/delete delimiters...

            C-M-\ (indent-region) still works to adjust indent levels (i.e., if somebody indented blocks w/ 2 spaces and your setup is 4 spaces), but it won't move code between blocks.

            Entering new code in python-mode is
    • by iguana (8083) * <davep@extend[ ].com ['sys' in gap]> on Wednesday September 08, 2004 @03:21PM (#10193974) Homepage Journal
      I use it daily in my job (http://www.mobl.com/handheld/cradles). Our test fixture (tests new boards coming off the line at our custom manufacturer) is written in shell scripts and Python on an embedded SiS-550 Linux board running 2.4.9, uClibc, BusyBox, etc.

      I rewrote our Windows-based management tools into Python for myself. Using that protocol library, I've sent quick and dirty py2exe wxWindows programs to customers. "Just unzip and run." Unless they look closely, I'm sure they don't know (and don't care) they're running Python apps.

      It's not exactly "in your face" like Zope but it glues together my day.
    • I'm still a beginner in Python, but in languages that ignore whitespace, incorrect indentation is the quickest way to turn me into a raving madman! A language that FORCES you to indent properly is GREAT!
      • Incorrection indention is corrected with almost a single click in any better editor, I really don't see it as a problem unless people are using notepad to write their programms of course.

        The problem with pythons whitespace is that it causes quite a bit more problems than it solves in my view. Especially when one refactors function and classes (make a local function a global or visa verse) it is just way to easy to break the code, since once you have broken the indention you have broken the programm and its
        • Such a reformatting command will only reformat you YOUR preferences, not necessarily anyone elses. There is no universal standard for an editor to reformat to. Braces on lines by themselves itself, or hanging on the end of the line above? Indent the braces with the code, or just the code itself?

          When you are maintaining code that you didn't write on a version control system, you almost certainly shouldn't be changing code just to reformat it. It causes diffs that are unrelated to meaningful changes in
      • A language that FORCES you to indent properly is GREAT!
        Then you need to look at RPG.

        The more things change, the more they stay the same:)

        Enjoy,

    • All I need to do now is find a shop that actually uses Python...


      Google, ILM, and NASA all use Python. See the Python Quotes [python.org] page.
  • by graveyhead (210996) <fletch AT fletchtronics DOT net> on Wednesday September 08, 2004 @02:39PM (#10193416)
    For those who haven't tinkered yet, or are just getting started with Python, I've found one of it's greatest strengths is it's ability to munge lists.

    e.g, look at this super-terse, but still legible, sub-array code:
    l = l[1:]
    List comprehensions are another great feature:
    l = [ do_something(x) for x in l ]
    This is so amazingly compact when compared with list processing in Java or C++.

    Anyhow, hats off to Guido Van Rossum for such a great language. I'll have to check this book out... I've been using the python cookbook (OReilly) and the documentation on the site almost exclusively...
    • Actually, I have a problem with lists comprehensions:

      With Python: [ x ** 2 for x in xrange(100000) if x % 2 == 0 ] (8 seconds)
      With Ruby: (1..100_000).select { |x| x % 2 == 0 }.map { |x| x ** 2 } (2 seconds)
      but Ruby is supposed to be 10 times slower (not compiled, bigger...) What's happening? (it's not a troll, it's a real question)
      • by Mendenhall (32321) on Wednesday September 08, 2004 @03:40PM (#10194198)
        Actually, that took me a while to figure out, too. If you try it with 50000 instead of 100000, on my machine python takes 0.384 seconds while ruby takes 0.537 seconds. With 100000, the comparison is much as you show (except about twice as fast in both cases). If, instead of squaring x, you take x alone, python is also faster.

        Apparently, there is something quite different about ruby's handling of long integers (>32) bits from python's. In the python case, this expression automatically switches to infinite-precision integers (at least for python 2.3). I don't use ruby, so I don't know what it is producing when the numbers get beyond 32 bits. Does it automatically go to long integers?

        Anyway, the speed difference in this pair of examples seems contrived to get ruby to do something much faster than python, since it requires 'special' values including integer overflow to exercise this effect. Maybe ruby really has better long integer handling than python. Can any on who knows ruby comment on the result of the overflow?
      • Just wanted to add one more for reference:

        With Python: (8 seconds)
        [ x ** 2 for x in xrange(100000) if x % 2 == 0 ]
        With Ruby: (2 seconds)
        (1..100_000).select { |x| x % 2 == 0 }.map { |x| x ** 2 }
        With Perl: (<= 1 second)
        map { $_ ** 2 } grep { $_ % 2 == 0 } (1..100000);
        • I would guess Perl is optimizing away the map in a void context, but this doesn't seem to be the case. I recall a while back some discussion about optimizing the .. operator to not always create a full-blown list unless necessary; these changes must have been implemented.

          On my system (using 1,000,000), Python takes 10 seconds, Perl takes 3. Even using @a=map { $_ ** 2 } grep { $_ % 2 == 0 } (1..1_000_000), forcing Perl to compute the list, Perl finishes in a mere 3-4 seconds. I ran these informal benchmar

          • by Anonymous Coward
            The optimization is utterly trivial: since from a certain point onwards, x**2 will no longer fit into a 32-bit integer, python has to coerce some ints into longs. If you do this beforehand, the difference is rather large: compare the original:

            a = [ x ** 2 for x in xrange(1000000) if x % 2 == 0 ]

            to

            a = [ long(x) ** 2 for x in xrange(1000000) if x % 2 == 0 ]

            using time, I get:

            [real: 0m21.790s; user: 0m20.290s; sys: 0m0.110s] for the first one, and [real: 0m3.637s; user: 0m3.310s; sys: 0m0.070s] for the sec
    • Does that include the spiffy stuff that you can do using boost? [boost.org] I haven't done C++ in a while so I haven't had a chance to really play with boost yet, but I'm led to believe that it lets you get the language down to about that level of compactness.

      Personally I'm a fan of (mapcar (lambda (x) ...))

    • List processing, huh? Witness what a _real_ list processor can do:
      (loop for x from 1 to 100000
      when (zerop (mod x 2))
      collect (* x x))
      0.16 seconds on my 1Ghz G4.
    • by Anonymous Coward

      l = l[1:]

      Granted. But

      l = l.subList(1,l.length()-1);

      ...isn't horrible. And in Lisp:

      (setf l (subseq l 1))

      ...is pretty good.

      List comprehensions are another great feature:

      l = [ do_something(x) for x in l ]

      Where the hell did Pythoners (and others) start using the incomprehensible term "list comprehensions"? Isn't the correct term ("function mapping" -- from Lisp, Scheme, Prolog, Mathematica, etc.) still sufficient?

      BTW, here's some simple code for doing mapping in Java. Yes, it can be mo

  • good and bad (Score:5, Interesting)

    by rjnagle (122374) on Wednesday September 08, 2004 @02:40PM (#10193434) Homepage
    Funny, I have been reading both the online version and the print version over the weekend.

    It is in many ways an excellent book, but geared towards more experienced programmers than I. The style is readable, but the program illustrating introspection (chapter 4 I believe) is really hard to get into. Mark could have chosen a better example.

    I particularly liked the way that Pilgrim annotated the code. He started out a chapter with the raw code, broke them into blocks with annotations and then concluded the chapter with a review.

    The approach of these diveinto books is to introduce unfamiliar concepts and then dissect them one by one. My only complaint is that sometimes he introduces a lot of things all at once. It would have been better (though less succinct) to use more examples with fewer concepts thrown together all at once. On the other hand, I can appreciate the succinctness of the example programs by presenting them without first dumbing them down. The good thing about diveintopython is that it helped me to read a program pretty easily --although that doesn't imply that I can apply this knowledge..Give me another week or two:) The key question is at what point do I feel like coding on my own? I tried the examples in chapters 1 and 2, and then didn't feel like I could start coding until I finished the first 8 chapters. (and am slowly getting the hang of it).

    Interestingly, when I started out, I found that I was referring to Oreilly's Python in a Nutshell [amazon.com] more and more. Didn't look that user friendly at first, now seemingly more useful.

    My sense is that programming is a matter of incremental mastery. (First read Fun with Dick and Jane, then read Wizard of Oz, then Melville, then Shakespearean sonnets). This book starts out by throwing out the Shakespearean sonnets at us and then explaining piece by piece until we have a sense of the whole.

    Guido von Rossum's tutorial is more of a stepping stone approach, though the example code is more academic than practical.

    One advantage of the online book: great hyperlinked references to Rossum's tutorial and other sources.

    Despite my griping, this was still a good instructive read (though challenging). And way to go Mark for putting this online for free!
  • It's also in Debian. (Score:5, Informative)

    by jonathan_atkinson (90571) * <jonathanaNO@SPAMcleanstick.org> on Wednesday September 08, 2004 @02:45PM (#10193497) Homepage
    If you use Debian, you can just:
    # su
    # apt-get install diveintopython
    And the book will be downloaded and placed into /usr/share/doc/diveintopython/

    --Jon
  • I think someone should write us a Dive into zope book with the same quality as Dive into python!
  • by mwood (25379) on Wednesday September 08, 2004 @03:05PM (#10193769)
    Fat language books are just, well, fat. I learned 98% of FORTRAN IV from a book about .75" thick, and my ALGOL 68 book is even thinner. It takes very little space to thoroughly introduce the programmer to Modula or Icon. Even COBOL books don't have to be wordy even though most COBOL code is.

    When I see a slender volume sitting among the telephone-directory-sized tomes, I usually pick it up on the assumption that it should be good if it's so lean. I am not often disappointed.

    (I just realized that LISP books *all* tend to be rather slender. McCarthy, Siklossy, and Steele all managed to say quite a lot in very little space. Hmmm.)
    • by Mr. Bad Example (31092) on Wednesday September 08, 2004 @03:11PM (#10193832) Homepage
      > (I just realized that LISP books *all* tend to be rather slender. McCarthy, Siklossy, and Steele all managed to say quite a lot in very little space. Hmmm.)

      It's because the chapters are recursive.
    • by njdj (458173)
      The thinnest language manual I've ever used was the BCPL manual, which described the full language and its library (with examples) in an A4-size manual less than 2mm thick. This was in the mid-1970s. Developed by Martin Richards at Cambridge (not sure when - 1970??), the language became popular at CERN and was used at the Lawrence Berkeley Laboratory and elsewhere, and influenced the design of C.
    • (I just realized that LISP books *all* tend to be rather slender. McCarthy, Siklossy, and Steele all managed to say quite a lot in very little space. Hmmm.)

      (Insert joke about parentheses (()) (here))

      I suspect that the Lisp books are so small because the number of concepts in Lisp is rather small. It's just that each concept in Lisp goes a long way.
    • Very true.
      I did a lot of Cobol when I started out ( I am old) and I had this 600+ page Cobol book but I never went past page 18 and it was well worn out all the way to page 18. What was on page 18? First example of more-or-less complex complete program.
  • Python (Score:4, Insightful)

    by jefu (53450) on Wednesday September 08, 2004 @03:07PM (#10193800) Homepage Journal
    A few years back I wrote some scripts for web input processing. I knew a smattering of Perl so wrote them in Perl. They worked ok as far as I could tell . I had other things to do so stopped working on them, then went back after a while to add some functionality and discovered that I had no idea what I had done or how. Eventually I worked it out and added the functionality I wanted (and comments, yup) and went away again. The next time I went back I had to learn the whole thing again and my comments and cleaned up code didn't help.

    So I'd heard about Python and that it was good, so (since I like the process of learning new languages) I decided to try rewriting the scripts in python. In about two days I had them doing everything the perl had done and the added functionality as well and with remarkably few bugs.

    Eventually I went back to add on more functionality and "Lo!" I had no trouble reading my Python code and even better adding in the new stuff was simple.

    The biggest problem with Python has been the lack of a good book, I'll be considering "Dive into Python" carefully - being in the education biz I'm looking for a really good Python book for students.

  • by reallocate (142797) on Wednesday September 08, 2004 @03:23PM (#10193995)
    >>... one gets the feeling that its primary purpose is to allow the author to make some payments on a car or mortgage...

    Geez, how did some people become so naive? Just figuring out that professional authors write for money? And you're offended by it?

  • I had no idea (Score:3, Interesting)

    by Cereal Box (4286) on Wednesday September 08, 2004 @03:28PM (#10194052)
    Mark Pilgrim works down the hall from me. I had no idea he wrote this particular book.

    Small world.
  • mirror (Score:4, Informative)

    by Kedder (529127) on Wednesday September 08, 2004 @03:32PM (#10194100) Homepage
    here is a mirror [faqs.org]
  • by nusratt (751548) on Wednesday September 08, 2004 @03:54PM (#10194393) Journal
    ...you would expect to go more like this:

    "...a dialog between him and his manager after showing him a rough 20-page draft:

    Manager: "This is really good. You could probably make some money off this someday --
    but you did it while employed by us, so now it belongs to us.
    Cough up the rest.
    You have a month."

    http://yro.slashdot.org/article.pl?sid=04/08/03/ 22 5217

  • site seems down to me so I'm wondering if anyone has started a torrent for the book?
  • by jalefkowit (101585) <jason@NOSPam.jasonlefkowitz.net> on Wednesday September 08, 2004 @04:12PM (#10194615) Homepage
    If you use ActiveState's free distribution of Python for Windows, ActivePython [activestate.com], the electronic version of Dive into Python is included in the documentation file under "Helpful Resources". Very handy!
  • by entrox (266621) <slashdot@nosPAm.entrox.org> on Wednesday September 08, 2004 @04:14PM (#10194643) Homepage
    If you like the more practical approach of books like this and always wanted to see what the fuss about Common Lisp is all about, then Practical Common Lisp [gigamonkeys.com] is for you. The book isn't finished yet, but some chapters are already online for review.
    Learn CL while writing a flexible MP3 database, a spam filter or a generic parser generator for binary files. How about a streaming MP3 server or a unit test framework? It's all in there without the boring stuff, which usually accompanies books like these.
  • by chris_sawtell (10326) on Wednesday September 08, 2004 @04:19PM (#10194694) Journal
    So here's the contents page from Google's cache:-
    Dive Into Python Table Of Contents [64.233.167.104]
  • mod_python/PSP (Score:5, Interesting)

    by noselasd (594905) on Wednesday September 08, 2004 @04:40PM (#10194949)
    You guys discovered mod_python [modpython.org] ?
    Which now comes with PSP. That is, server side web scripting using
    Python as the language. Similar in spirit to PHP, just using Python.
    Amazingly much more fun than PHP.
  • by otisg (92803) on Wednesday September 08, 2004 @05:45PM (#10195566) Homepage Journal
    As a co-author of an upcoming technical book (Lucene in Action [manning.com] - not a plug, just providing context), let me just address this:


    Reading them, one gets the feeling that its primary purpose is to allow the author to make some payments on a car or mortgage.


    Unless we are talking about a book that really interests a LARGE portion of the geeks out there, the above statement is really missing the point. I don't know any technical book authors who do it for the money. I am certainly not writing for the money. Royalties are nice, but they are really small in the end, especially when you consider the time and effort that you put in writing technical books. In addition, think about the 'life expectancy' of a book that covers a technical topic - not much longer than firefly's.


    Long story short, one doesn't write this type of stuff to make money, and Mark certainly didn't write Dive into Python for $$$ - I've had it bookmark in my Simpy account (URL in sig) for 6+ months now. I just wanted to get this straight, so there is no confusion. This may also be interesting to those considering writing a book on a technical topic.

  • why didn't the author think to utilize NYU's Coral [nyu.edu] content distribution network (covered [slashdot.org] here on /. just a couple weeks ago) to keep the bandwidth off diveintopython.org? Now it's too late, since Coral can't access the site to get it in the cache.
  • by starkaudio (808545) on Wednesday September 08, 2004 @09:19PM (#10197163)
    Drooling to give it a read, but can't get to the site? The previous link was to a version from 2002. If you go to google and search for anything along the lines of "diveintopython_5.4.orig.tar.gz" you'll find the May 20th, 2004 version is on many linux distro sites. Enjoy!

Any given program, when running, is obsolete.

Working...