Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×

Beginning Python: From Novice to Professional 436

nazarijo writes "Python seems to be devouring everything these days, with more and more people using it for serious projects. It's quickly supplanting Perl in some circles, and with good reason. It's a powerful, richly featured language with boatloads of extensions. And, unlike Perl, it's very easy to do complicated things in simple, legible code. Python books are still only a small part of the shelf at your local bookstore when you compare it to the popularity of Perl, but which ones are the gems and which ones are fluff? Having looked at a lot of Python books in the past couple of years, I think that Beginning Python: From Novice to Professional is the one that I'll most recommend to people." Read on for the rest of Jose's review.
Beginning Python: From Novice to Professional
author Magnus Lie Hetland
pages 604
publisher Apress
rating 8/10
reviewer Jose Nazario
ISBN 159059519X
summary Tour the Python language, from basics to advanced modules


Beginning Python is loosely grouped into three main sections. The first deals with Python fundamentals, all the goodies that are inherent to the language and the modules that it ships with. It's surprising to see how rich the language is out of the box, especially when compared to some other scripting languages. The second section would be the chapters covering popular extensions for a variety of services. These include network and web programming, SQL objects, and even GUI programming. And finally the third section is a set of 10 projects in Python, which bring everything together in a concise fashion.

I like this book a lot because it is very clear in its delivery, both the prose and the code examples used, and is consistently Pythonic. The Python language lends itself to a powerful programming style and, unlike Perl, many Python developers I know don't bother with a dozen ways to perform a simple action, they get it done and move on. What you wind up with is clear code that's easily understood by someone new to the language.

Unlike what the title would suggest, Beginning Python isn't only for the first few weeks with the language. The book is large and in depth, and the coverage of material is fantastic in many ways. You get a quick tour of the basics and then you move on to an overview of the language and then its common features. The inclusion of the 10 projects is another benefit to the intermediate user. She can refer back to this book for additional information and pointers from time to time, it wont sit still on her shelf.

That said, there are a few things in the book that I tend to disagree with. For example, the author dissuades you from using destructors in your code, but in my experience they're far more reliable, and a better place to do some cleanup, than he states. A few chapters are also a bit skimpy when they didn't need to be. For example, Chapter 18, which covers packagers like the distutils component from Python, needed to be fleshed out a lot more. This is a powerful feature in Python and sound docs on it should just be there. There's no reason to hold back on something so vital. The section on profiling in Chapter 16 is also a bit thin around the middle when it needn't be. While this seems like a minor point, having a reference to speeding up code (and measuring the improvements) is always nice. And finally, Chapter 17, which covers extending Python, is simply too short for its own good. A more in depth example would have been appreciated.

I have begun recommending this book to people I know that are smart and program in other languages, but aren't very familiar with Python. Many beginners books only take a person so far before they become a useless item on the shelf. This means that he $30 or more that was spent is now gone, so I've grown to be observant of how long I expect a book to be useful. I anticipate the useful shelf life of Beginning Python will be longer than average for most general purpose programming books for a single language. What's more is that it's not a dry reference book. Couple this to a Python cookbook for recipes and you have a two volume "mastering Python" series.

If you've been curious to learn Python and haven't yet found the book that speaks to you clearly, this may be the one. I'm pleased with the quality of the writing, the examples, and the quick pace of the book. While it's nearly 30 chapters in length, most of them are short and focused, making them easily digestible and highly useful. Overall probably the best Python books I've had the good fortune of reading."


You can purchase Beginning Python: From Novice to Professional 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.

Beginning Python: From Novice to Professional

Comments Filter:
  • O, yeah? (Score:3, Insightful)

    by Anonymous Coward on Wednesday January 11, 2006 @03:35PM (#14447975)
    "And, unlike Perl, it's very easy to do complicated things in simple, legible code."

    Perhaps it is time for you to get a perl book or take CS-101 course or something.
  • by LionKimbro ( 200000 ) on Wednesday January 11, 2006 @03:35PM (#14447983) Homepage
    I have tried to do as much research as possible myself, but it seems that everyone I ask just woke up one morning, and found themselves to be able to program three or more languages (in other words, they do not remember how they started out).

    Ha!

    Insightful.

    Yes, yes, true.

    I skilled up when young, by typing in programs from the back of Family Computing.

    I don't know what to tell "kids these days."

    Entering computer programs, by hand, worked well for me.
  • Re:Devouring? (Score:4, Insightful)

    by GigsVT ( 208848 ) * on Wednesday January 11, 2006 @03:36PM (#14447989) Journal
    That's not a good measurement.

    Those are unfilled jobs. Jobs that they couldn't find someone for without resorting to advertising. In other words, the jobs that get listed on job sites are the ones that no one wants.
  • by Anonymous Coward on Wednesday January 11, 2006 @03:42PM (#14448045)
    And, unlike Perl, it's very easy to do complicated things in simple, legible code.

    This must mean you aren't able to write legible Perl code. Perl has been making complicated things simple for more than a decade. If you don't know how to write clean code, then your Python will also suck.

  • Re:Devouring? (Score:1, Insightful)

    by Anonymous Coward on Wednesday January 11, 2006 @03:42PM (#14448048)
    It said devouring, not devoured ... meaning it is all
    about dynamic grouth.
    Do the same query one more time in a month and then
    compare numbers. Ones that change faster are the ones
    that deserve "devouring" attribyte.
    Pretty sure, Python will be one of them
  • by engagebot ( 941678 ) on Wednesday January 11, 2006 @03:47PM (#14448092)
    Also interesting to note that many universities start students programming in C. The reason they do is because they want computer science students to get a good understand alot of what's going on in the background, not just learning a specific language.

    The kicker: If you understand the principles behind it, you can easily learn any language.

    You probably want to skip alot of the theory behind data structures and whatnot at the beginning though.
  • by AthenianGadfly ( 798721 ) on Wednesday January 11, 2006 @03:48PM (#14448108)

    And, unlike Perl, it's very easy to do complicated things in simple, legible code

    The issue with Perl isn't that it's particularly hard to do complicated things with simple, legible code (not more so than a lot of other languages, anyway), but that it's very, very easy to do something extremely quickly, which often - but not always - means code that makes sense at the time but isn't necessarily readable, or leads to overly terse code. Yes, Perl makes it easy to do things wrong (and a lot of people out there do use Perl to make unreadable programs), but that doesn't mean that it can't be used to do things correctly as well as any other language.

  • python regexes (Score:2, Insightful)

    by funkelectric ( 931604 ) on Wednesday January 11, 2006 @03:48PM (#14448111)
    After hacking perl for over 10 years, Python sounds very good. The first program I tried to write in Python was the quick-and-dirty thing I need most: Read a file and parse it using regexes. Perhaps I stumbled upon the one area where Perl shines in comparison with Python, for that is the impression I got. The Python regex methods do not seem a natural fit for the problem.
  • by Just Some Guy ( 3352 ) <kirk+slashdot@strauser.com> on Wednesday January 11, 2006 @03:50PM (#14448131) Homepage Journal
    if you have to modify it, even a little, every time you port it to a new operating system, you can hardly call it "platform independent".

    Out of curiosity, what other language qualifies as platform independent by your definition? Answer: there isn't one. In the context of what we currently have, today, in 2006, Python is just about as platform independent as anything else.

  • by Myddrin ( 54596 ) on Wednesday January 11, 2006 @03:57PM (#14448202) Homepage

    And, unlike Perl, it's very easy to do complicated things in simple, legible code.

    This must mean you aren't able to write legible Perl code. Perl has been making complicated things simple for more than a decade. If you don't know how to write clean code, then your Python will also suck.

    Not directed at the parent, but at the Perl-snipping in the original post....

    <RANT>

    I'm a professional python programmer, and I've been making my living at it for a number of years now. (It was my embracing of python that allowed me to transition to a 100% MS free workspace.) I started using it a project a few years ago, and it's just stuck for a number of reasons. (meta-classes, extensibility, etc.)

    One thing that drives me buggy about some python evangelists, (and many evangelists, in general) is the need to bash anything that is not their favorite brand (be it Creative vs iPOD, Python vs (insert any language here). And so on. The fact of the matter is that Perl is a perfectly good language. I don't use it on a regular basis personally, but I've seen, read and understood a good deal of Perl code w/o a hassle. (yes, I've seen some scary code, but I've seen scary code in C++, Python, Java, etc., etc., etc.)

    Sometimes we just have to admit that there are multiple good tools that we could use, but we have a personal (and possibly irrational) preference for one over the other. That's life as a human being (which I'm assuming at least 99% of the readers out there are. :) ). Just because some people use Perl, doesn't make my choice of python (of C++, my other "main" language) any less valid.

    It's real life, not a multiple choice test -- there is no single "correct" answer.

    </RANT>

    Ok, I'm done... back to work.

  • by Anonymous Coward on Wednesday January 11, 2006 @04:01PM (#14448245)
    My recommendation is pick up a beginners PHP* book. Start writing code it in as soon as you pick it up. Just as you read, write code. Once you've finished with that book, make 1 or 2 medium projects for yourself and try coding them until you feel fairly familiar with the language. Once you do that, pick up an intermediate or advanced php book and read that. Then go back to your code for the projects you did for yourself and rewrite it or write on top of it. You'll soon see how not only to write PHP, but also how to write rewritable code as well as maintable code. Rinse and repeat.

    * You can replace PHP with any other language. Although I recommend PHP just because it's a fairly simple and widely used language.
  • by bcrowell ( 177657 ) on Wednesday January 11, 2006 @04:02PM (#14448253) Homepage
    And i came to the conclusion that Python is very close to a perfect place to start learning programming.
    I've used python as a language to teach people programming (in the context of a physics course, to do numerical simulations). It was OK, but the significance of whitespace was a major barrier for them to overcome. If I was doing it over again today, I'd probably use Lua, which has a very standard C-like syntax. Another consideration is that it might be good to use a language that's small enough to run in a web browser [hobix.com].

    Python's strengths, AFAICT, are its pure object-oriented design and the large set of libraries available for it. IMO, neither of these are particularly important for teaching beginners to program.

  • by jbellis ( 142590 ) <jonathan@carDEBI ... com minus distro> on Wednesday January 11, 2006 @04:09PM (#14448330) Homepage
    For various reasons (more mature stdandard & third party libraries; English docs; real threading support -- this is a big one; etc) Python is a much better general-purpose language than Ruby.

    (It's also about twice as fast, but honestly if Ruby is too slow for your project a factor of 2 probably isn't going to save you. Still, speed is a nice bonus.)
  • most helpful book (Score:2, Insightful)

    by engagebot ( 941678 ) on Wednesday January 11, 2006 @04:11PM (#14448346)
    I think the book thats most helpful to the novice programmer wouldn't be a book about any language at all.

    It'd be a book about programming and algorithms in general. Its MUCH easier to root around in a 'hello world' program or the like if you understand things like loops, if/then/else statments, function calls, etc. Even the fundamental idea of declaring and using a variable.
  • Re:O, yeah? (Score:5, Insightful)

    by Just Some Guy ( 3352 ) <kirk+slashdot@strauser.com> on Wednesday January 11, 2006 @04:16PM (#14448388) Homepage Journal
    "And, unlike Perl, it's very easy to do complicated things in simple, legible code."

    Perhaps it is time for you to get a perl book or take CS-101 course or something.

    I've got both. So, tell me: what's the syntax for returning multiple complex objects from a function in such a way that they don't have to be dereferenced by the calling code (that is, they can be used directly, just like you were returning a single scalar)?

    Python example from the interactive shell:

    >>> def foo():
    . return {'one': 'ein', 'two': 'zwei'}, lambda x: x + 5, str
    >>> a, b, c = foo()
    >>> a['two']
    'zwei'
    >>> b(5)
    10
    >>> print c.__doc__
    str(object) -> string

    Return a nice string representation of the object.
    If the argument is a string, the return value is the same object.

    I'm not overly stupid, but doing something so relatively easy in Perl put me at my limits. I like Perl, and I've written many large programs in it, but I always had to fight against the syntax. Python got out of the way and let me concentrate on logic instead.

  • by toupsie ( 88295 ) on Wednesday January 11, 2006 @04:16PM (#14448393) Homepage
    And, unlike Perl, it's very easy to do complicated things in simple, legible code.

    So can Perl.

  • by mrfoos ( 584110 ) on Wednesday January 11, 2006 @04:17PM (#14448396)
    Comparing to two for me is like comparing tree cutting with building houses.

    When you build a house you need an architect and specific design rules so other people in the project can do their part. It takes a long time to build it, and someone has to live in the house a long time.

    When you cut down a tree you're only interested in the fastest way possible to get it down safely. Who cares if it's pretty. If you didn't like the way the first one fell, you can make adjustments on the next.

    A house builder wouldn't tell a woodcutter which axe to use. He doesn't care. Of course, woodcutters have no business building houses.

    Personally? I like being a lumberjack. Nothing like fervorishly hacking away and yelling "TIMBER!" from a safe distance.
  • Re:My 2 scents (Score:2, Insightful)

    by Anonymous Coward on Wednesday January 11, 2006 @04:22PM (#14448448)
    Run "pychecker" on your python scripts. It catches all sorts of things; certainly almost anything having to do with misspelling.
  • Re:O, yeah? (Score:3, Insightful)

    by Coryoth ( 254751 ) on Wednesday January 11, 2006 @04:27PM (#14448491) Homepage Journal
    "And, unlike Perl, it's very easy to do complicated things in simple, legible code."

    Perhaps it is time for you to get a perl book or take CS-101 course or something.


    It is, I quite agree, entirely possible to write fairly simple clear legible code in perl. It does require a few extra hoops, but in general it isn't that hard, it just requires a fair bit of self-discipline or, if you're working in a team, some very rigid well defined coding standards ... that everyone sticks to. From my point of view, if you're at the point of bothering to have and enforce coding standards, why not just enforce them at the language level? The compiler/interpreter can then tell you whether you're meeting appropriate standards, and does a much better job of ensuring everyone actually conforms to a consistent interpretation of the standards. In effect that's what Python does to a certain extent (and you can also find it in other languages like Eiffel and Ada). I perfectly understand that such strict and required enforcement isn't always necessary or desireable - not every software project has maintainability and legibility of code as a primary concern, and if you're just coding by yourself obviously you'll always meet your own standards - but if you are serious about maintainability then, to my mind, language enforced coding standards and a certain amount of "one right way to do it" has real value.

    Jedidiah.
  • Re:O, yeah? (Score:3, Insightful)

    by chromatic ( 9471 ) on Wednesday January 11, 2006 @04:34PM (#14448544) Homepage
    ... if you're at the point of bothering to have and enforce coding standards, why not just enforce them at the language level?

    Because the language designer probably doesn't know as much about your team and the problems you're trying to solve as you do.

  • Re:O, yeah? (Score:5, Insightful)

    by Parity ( 12797 ) on Wednesday January 11, 2006 @04:43PM (#14448622)
    That's a really foolish argument. Of course you have to make references and dereference to do the same thing in perl, because perl is a pass by value language; python is a pass by reference language.

    In perl you have to be explicit to dereference.

    In python you have to be explicit to copy.

    Your case happens to be one where references are needed, and in python, implicit. In cases where copying of arrays is need, python needs to be explicit; perl is implicit. So ignoring the ridiculous 'without dereferencing' restriction:

    sub foo {
      return { 'one' => 'ein', 'two' => 'zwei' }, sub { my $x = shift; return $x + 5; }, "string"
    }

    my ($a, $b, $c) = foo();

    print $a->{'one'};
    print $b->(5);
    print $c;

  • by Just Some Guy ( 3352 ) <kirk+slashdot@strauser.com> on Wednesday January 11, 2006 @04:54PM (#14448729) Homepage Journal
    I like (good) static typing precisely because it saves me effort

    Many of us - both beginners and not-so-beginners - like dynamic typing for the exact opposite reason: things that would be errors in statically typed languages are perfectly acceptable in dynamic language. Implicit, pervasive polymorphism can let you create some very robust code in a relatively short amount of time. Writing "foo_int", "foo_string", "foo_float", etc. gets a little old, even if it does give you some explicit guarantees about the data you're manipulating.

  • Re:Devouring? (Score:5, Insightful)

    by Decaff ( 42676 ) on Wednesday January 11, 2006 @04:55PM (#14448745)
    Python is better than Perl, but in terms of devouring? Its like saying that American Football is devouring other sports around the world.

    You are forgetting that this is the Slashdot Universe, where...

    "Java/Intel/Oracle/Sun/Windows is dying..."

    "No-one uses commercial UNIX..."

    "Open Source is GPL and anything else is evil.."

    "PHP scales for everything...."

    and...

    "Favourite open-source language [fill in the blank] is the future and everyone is already using it...."

    When in this Slashdot dimension, you have to understand the rules!
  • Re:I tried python (Score:1, Insightful)

    by Anonymous Coward on Wednesday January 11, 2006 @05:01PM (#14448813)
    Examples please, or you're just FUDing.
  • Re:Devouring? (Score:3, Insightful)

    by smallpaul ( 65919 ) <paul@@@prescod...net> on Wednesday January 11, 2006 @05:04PM (#14448835)
    Job descriptions trail language popularity because they are driven by the need to replace people who were working on pre-existing projects. If every programmer decided to day to switch to Intercal, that wouldn't seriously show up in the job postings until a few years from now when the code needs to be maintained.
  • by Rei ( 128717 ) on Wednesday January 11, 2006 @06:04PM (#14449375) Homepage
    then it becomes a problem that can be difficult to find

    Only if you already have a variable called 'strikr'. Otherwise, you'll get a runtime exception. Not having to initialize variables is completely different from "all variables come pre-initialized to some value". If you type "a=b", b better be defined. It doesn't have to be *declared* (nor does a), but it must contain a meaningful value (which could be None - python has a concept of null).

    vulnerable to pretty printers

    Who would run some random code formatter on their code when it's not designed for their language? That's just idiocy. Even still, if it treats "4 spaces" in one place as the same as "4 spaces" in another, the code will still work - python just cares that you're *consistant* with your indentation. Meanwhile, with C/C++, you can shove the brackets almost anywhere and do the most bizarre indentation imaginable, and it's perfectly content with you - bad form.
  • by Tony ( 765 ) on Wednesday January 11, 2006 @06:07PM (#14449395) Journal
    In Perl, it is easy to make legible code, and it is easy to make illegible code.

    In Python, it is easy to make legible code, but it is difficult to make illegible code.


    That's because Perl is versatile, flexible. Python forces you to do things The Python Way(tm). I've tried Python a couple of times, and I keep going back to Perl. Maybe I'm just a rebel, but I don't like a language telling *me* what to do (queue "In Soviet Russia..." joke here).

    And, yes, I mostly just hate the whitespace-as-blocking braindamage. It's like Guido loved LISP, but hated the braces, so he re-invented LISP, poorly. But that's why I love programming-- everybody gets to choose their favorite poison.
  • by pileated ( 53605 ) on Wednesday January 11, 2006 @06:07PM (#14449400)
    I don't think that it's harder at all to be legible in perl. It's just that unfortunately perl culture encourages illegibility. A great book that doesn't is Damian Conway's recent Perl: Best Practices. What a breath of fresh air to see someone say that perl ought to be legible. Sad to say I think that the things that brought perl to it's early prominence are also the things that have hurt it in the long run: the ability to do something complicated extremely quickly. Unfortunately this seems to have encouraged "clever" programmers, who use every clever perl trick in the book. All that cleverness has become part of perl culture.

    Oddly enough I'm reading a book on Applescript right now (not because I really want to but because I need to write some fairly complicated scripts in it.) The book reminds me of perl in it's early days when it says how easy it is to do something or how Applescript magically does something for you, like understand whether you're in a string or math context. This seems good to beginners. But it the long run I think if lends itself to muddled code. There's just a little too much congratulations to each language for it's cleverness (and perl definitely is clever).

    As far as Python goes god knows I tried to read either Programming or Learning Python but I just gave up. It just didn't hold my interest at all. Give me Java, or legible Perl any day!

  • by Just Some Guy ( 3352 ) <kirk+slashdot@strauser.com> on Wednesday January 11, 2006 @09:09PM (#14450613) Homepage Journal
    Python is portable, too. But it's still possible to write non-portable code, such as Windows programs that call COM objects, or Unix programs that create device nodes.

    Basically, if you stick with the core modules and don't hardcode pathnames or do other bad things, then your programs will be portable. Venture past that, just as with any other language, and all bets are off.

  • by Hosiah ( 849792 ) on Wednesday January 11, 2006 @09:20PM (#14450669)
    And, unlike Perl, it's very easy to do complicated things in simple, legible code.

    I just burned through the flamewall on this issue not three days ago. I use Python instead of Perl, love Python best of all languages currently, and may even like the book reviewed. But it is superstitiously ignorant to declare any language makes it "easier" to program in. Can we just once have a discussion of the strengths and weaknesses and merits and demerits of any language at all, instead of talking about it like it was a laxative? "Makes the code soft and it flows out smoothly!" No, it doesn't: nothing does; hard programs are hard to write, easy programs are easy to write. I'll even save the time and copy my closing argument from last time:

    I know a secret. It's a secret you only find out after programming for a while. It's one you obviously don't know if you ask me which programming language is the "easiest".

    There is this public perception, unanimous in user-land, and even permeating to the very depths of Slashdot, which goes: "Computers are only hard because evil computer programmers deliberately set out to make them hard." And the secret is: that that's a falsehood. Computers are not made artificially difficult. It does no good to tell you this; this is a special kind of secret that you can only learn through experience.

    The experience of struggling to design a usable user interface for your own system. The struggle to overcome the barriers of closed systems, lack of documentation, and misinformation everywhere you turn. The exasperation of dealing with users who come to you with the attitude that your program broke on purpose, you should fix it without knowing what the error was, and it's too hard to learn anyway because you make it difficult, because you're "evil".

    Programming experience erases that mental line drawn between user and programmer. You get experience on both sides of the fence, and eventually you see that there is no such thing as artificial complication. Interfacing with a machine upon which we have taught electricity to think and where we hope to make it sing and dance for us is inherently complicated TO START WITH, and the various tools we use to perform our tasks - why, each and every one was written by average people like you and me who also sat down with a clean file and furrowed their brow and wondered "How can I do this? How can I make it so people will use it?"

    No, you still have that mental mindset that there are programmers who deliberatly design things to be difficult, that it's all in spite, that they're laughing at you. Who, except as a joke, would deliberately make a programming language "hard to learn"? To fail at your task and blame your tool is simply a form of denial so that you don't have to face the fact that you have given up on trying to use something (no matter if it's COBOL or Javascript or Perl or freaking TECO, even!) that hundreds of other people have used successfully.

    There is no "easy". There is no "hard". There is only "Task".

    Now, you want to talk about an "easy" language? Binary, of course! Binary has just two commands (one and zero) so it's the fastest to learn, has cross-platform compatibility built-in (all computers know binary!), is easiest to test (no compiler or interpretter required, just "Rite 'n' Run"!), is readily available everwhere (ALL programs are "open source" in binary!), and needs no extension libraries (Binary can do it all!). If you thought this paragraph was stupid, this is how stupid the rest of you sound to me when you hyperfocus on "easy" and act like there's no other aspect to programming.

UNIX is hot. It's more than hot. It's steaming. It's quicksilver lightning with a laserbeam kicker. -- Michael Jay Tucker

Working...