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 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:
  • by chriss (26574) * <chriss@memomo.net> on Wednesday January 11, 2006 @03:26PM (#14447907) Homepage

    Not only is this a good book, it is also one of only few that cover Python 2.4. The author Magnus Lie Hetland has a free python tutorial ("minimal crash course) (Instant python [hetland.org]) on his homepage. He was also involved (as author, editor etc.) in several other book projects:

    So we can assume he has a clue what he is writing about.

    His homepage [hetland.org] uses PHP, btw.

    Chriss

    --
    memomo.net - brush up your German, French, Spanish or Italian - online and free [memomo.net]

  • Damn perl bashing (Score:0, Informative)

    by Anonymous Coward on Wednesday January 11, 2006 @03:28PM (#14447917)
    Perl is as legible as the author makes it.

    By the way, you have fun with that whitespace requirement.
  • Re:being python (Score:3, Informative)

    by masklinn (823351) <slashdot.org@maskli n n .net> on Wednesday January 11, 2006 @03:30PM (#14447925)
    Not by far much, and Monthy Python based jokes are higly valued in Python the community and appreciated in python code/comments.
  • Devouring? (Score:5, Informative)

    by MosesJones (55544) on Wednesday January 11, 2006 @03:31PM (#14447945) Homepage
    Python seems to be devouring everything these days... even replacing Perl

    From Dice.com

    Python : 545 matches
    Perl: 3809
    C#: 3850

    Ummm over 1/8 of the demand of Perl or C#

    Java: 11856

    Java+BEA: 621

    So Python is smaller than one specific application servers development requirements.

    Python is better than Perl, but in terms of devouring? Its like saying that American Football is devouring other sports around the world.

  • On a related note... (Score:3, Informative)

    by Just Some Guy (3352) <kirk+slashdot@strauser.com> on Wednesday January 11, 2006 @03:32PM (#14447947) Homepage Journal
    For a quicker introduction to the language, you might look at the article I wrote [freesoftwaremagazine.com] for Free Software Magazine [freesoftwaremagazine.com]. It's not an in-depth analysis by any means, but should get you acquainted with the basics in under 10 minutes.

    It's licensed under the Creative Commons "Attribution-Share-alike" License, so feel free to pass it around if you want to.

  • by dmeranda (120061) on Wednesday January 11, 2006 @03:33PM (#14447964) Homepage
    Python Cookbook, Edition 2 also covers version 2.4. And it is also a very useful book, even for those who know Python quite well...you can always learn a few new tricks.

    http://www.oreilly.com/catalog/pythoncook2/ [oreilly.com]
  • by Colonel Panic (15235) on Wednesday January 11, 2006 @03:37PM (#14447991)
    I would check out How To Program [pragmaticprogrammer.com] by Chris Pine. It's very much for people who have no programming experience.

    Also, for a very different, novel and fun approach you should check out Why's Poignant Guide to Ruby [poignantguide.net]. Did I mention it was fun? It's also a great intro for someone who has never programmed before.
  • by Just Some Guy (3352) <kirk+slashdot@strauser.com> on Wednesday January 11, 2006 @03:38PM (#14448001) Homepage Journal
    What I am looking for, is some easy language to either script or program. Would python provide a good starting environment?

    Absolutely! I think it's one of (if not the) best languages for new programmers. My main reasons are:

    • It has a very simple syntax.
    • The core language is relatively tiny - there aren't many keywords that you have to learn just to get started.
    • It is strongly, dynamically typed, which means that you can spend more effort on telling your program what to do rather than the nitpicky details of how to do it.

    Opinions will vary, of course, but I think that Python is an excellent choice to start with.

    Have any of you been at my level, then learned python?

    Nope. When I was at your level, I had to learn a lot of really awful languages because the average person didn't have access to the nice ones. I would have loved having something so easy to learn and powerfully expressive at the same time.

  • by JTorres176 (842422) on Wednesday January 11, 2006 @03:39PM (#14448010) Homepage
    Python was the very first language I used to learn to program. I had multiple people telling me to start with python, so I perused over to their site, picked up a few online tutorials to go through, and started building a library of python books.

    It helps because I can write one program for Linux, it works on my Windows PC with minor mods, and even works on my wife's Palm with similiar minor mods.

    Python is a platform independant object-oriented programming language. It's great to learn, and it's great to start your learning with.
  • by Rei (128717) on Wednesday January 11, 2006 @03:41PM (#14448041) Homepage
    Actually, yes, I would definitely recommend it. I started programming before Python (actually started in Basic because it was the only thing I had in 7th grade, then ran as quickly as I could away from it to a real language). However, python is a very easy language to learn and you don't need to deal with any advanced concepts to "make things work".

      * You don't have to declare variables
      * Code blocks are simply based on how you indent, making it always very legible
      * You can easily see what functions are available in a package using dir(), and you can get brief help information on a function by print function.__doc__, from within any python shell.
      * Very simple to do things that might take a long time to in lower-level languages - reading contents of files, splitting strings, performing regular expression matches, etc.
      * Performance is tolerable for most applications - just don't try to write Quake or physics calculation software in it.
  • by AuMatar (183847) on Wednesday January 11, 2006 @03:41PM (#14448042)
    No it isn't. The AI scripts are. THe engine is C++.
  • Re:Damn perl bashing (Score:5, Informative)

    by Metasquares (555685) <slashdot&metasquared,com> on Wednesday January 11, 2006 @03:47PM (#14448090) Homepage
    It is a bit harder to be legible in Perl than in other languages, to be fair, especially if you use regexps (but then, they're not all that legible anyway to begin with). Still, you get used to it after a while and it becomes as easy to read Perl as any other language.
  • by gabe824 (772563) on Wednesday January 11, 2006 @03:47PM (#14448093)
    My first language was C, learned in a first year university introductory programming course, but when friends have asked me about learning programming I have recommended they start with python and the book How to Think Like a Computer Scientist: Learning with Python http://www.ibiblio.org/obp/thinkCSpy/ [ibiblio.org]. Its available free online. This is a good introductory book with no expectation of prior experience that teaches the ideas behind programming, not just the syntax of the language.
  • Dive into Python (Score:4, Informative)

    by Jazzer_Techie (800432) on Wednesday January 11, 2006 @03:48PM (#14448110)
    No discussion of Python literature can be complete without mentioning Mark Pilgrim's Dive into Python [diveintopython.org], which is an excellent way to get to know the Python language. It's free for download in a variety of formats. Two caveats however, being that 1) it hasn't been updated in about a year and a half and 2) it assumes that you already have a pretty good grasp of programming in some other language. But if you've you got some coding experience and want to take a serious look at what Python has to offer, this is a great book full of nice examples (with the code available for download as well).
  • by chriss (26574) * <chriss@memomo.net> on Wednesday January 11, 2006 @03:53PM (#14448170) Homepage

    Since this is inevitable to pop up, a very simplyfied version (slightly offtopic):

    Why not ditch Python and use Ruby (on Rails)?

    • Ruby is a nice language. It looks more like Java (or C or Perl) than Python, so that may be an advantage for those who dislike Pythons whitespace handling (I think it is genius)
    • Rails is a very nice framework for developing database driven web-apps very fast
    • Someone (David Heinemeier Hansson) really cared to make this user/developer friendly. There is good marketing, nice screencasts (although basically smoke and mirrors), good documentation, a well structured central web site, lots of support. All this may be even more important than the technical differences to other platforms like Python.
    • It's hype, so you could easily sell it to management

    Why better stick with Python?

    • Most of the hyped features Rails are available on Python too, although not yet in such a nice package. The Turbogears [turbogears.org] folks try this, but in a more pythoniac way. I like it better, since they actually bundled already established products like CherryPy and SQLObject instead of simply writing from scratch. This may not result in a smooth package like RoR, but it is more clearly aimed at the integration of other products.
    • There are tons of modules and documentation for Python out there. So if you come to the point where you want to include other features than those already present in your framework, it will be easier to add them from different sources, because a) there are more and b) integration is a more established process.
    • There has been a lot going on in the RoR aftershock to improve the situation, like discussions about merging the different frameworks (Turbogears/Subway) to create a unified and very powerful platform.
    • There is always a way up in Python with Zope (although this is a beast and documentation is bad, 3.X is much better, but lots of products currently still require 2.X) and integration in J2EE.
    • Python is old. There has not only been one generation of developers whos projects failed, but many. RoR is still in the "early adaptors" phase, where everyone sees the revolution and casualties are accepted. Ruby alone has had a strong following in Japan, but for the rest of the world Rails was the first contact. Wait a year until the "RoR sucks" postings appear, than you'll be much wiser.

    Chriss

    --
    memomo.net - brush up your German, French, Spanish or Italian - online and free [memomo.net]

  • by CoderBob (858156) on Wednesday January 11, 2006 @03:58PM (#14448210)
    Like some have mentioned, Python is a great place to start learning. It's platform indpendent (point #1), object-oriented (point #2), and not VB or Java (points 3, 4, 5, 6, and 7.)

    My hatred of Java and VB aside, however, I would add this: Once you get a good grasp of how to program in Python, it would be time to cut your teeth on a lower-level language. C or C++ would work here. It's going to be a little rough, as you get used to the different requirements, but you'll learn a lot more about Comp Sci.

    Also, and this could possibly go before you learned C or C++, you may wish to take a look at design patterns once you get the basics down. Addison Wesley has an excellent book on patterns here [amazon.com] (No, there is no referer BS in the link) which I encourage you to look at.

  • by Zathrus (232140) on Wednesday January 11, 2006 @04:00PM (#14448235) Homepage
    No it isn't. The engine and the AI are written in C++. All of the game scripts (map generation for example) and interface is in python, all the game data is in XML, and it's highly modable [civfanatics.com].

    The AI can be reprogrammed in C++ using their API. See Question 6 [slashdot.org]. I'm not positive that it's been released yet though.
  • by warewolfe (877477) on Wednesday January 11, 2006 @04:03PM (#14448257) Homepage
    I've had good experiences with O'Reilly in general, and with "Learning *", "Programming *", and "* Cookbook", where * has been Python, Perl, PHP. However, have a look at http://python.oreilly.com/ [oreilly.com] and download the free chapters and source code before you buy. For an intermediate level programmer you can probably do without the "Learning Python" book. Good Luck.
  • by Jason Earl (1894) on Wednesday January 11, 2006 @04:04PM (#14448264) Homepage Journal

    For the most part Python software written on one platform will work just fine on any platform with Python installed. Python is completely portable in that manner, and official Python interpreters are available for a ridiculously wide array of platforms. However, if you don't take that portability into account when you start writing your software it is pretty easy to write bits that won't work when you move them to a platform with significant differences. For example, Python has APIs that deal intelligently with the various path separators, line endings, etc. that folks that write software for various platforms deal with every day. However, it's fairly easy to ignore these tools and do things like hardcode 'c:\MyDirectory\' into your application.

    It is also possible to write Python software that uses third party Python extensions written in C or C++ that haven't been ported everywhere. Of course, this is possible in every "platform independent" language that I have heard of. It's certainly possible to do this with Java (witness IBM's SWT).

  • Learning Python (Score:3, Informative)

    by kevin_conaway (585204) on Wednesday January 11, 2006 @04:09PM (#14448327) Homepage
    I am a Java programmer by profession but I wanted to give Python a shot because it seemed like fun.

    As a programmer experienced with OO programming and some other types of "scripting" languages, all I needed to read was Learning Python [oreilly.com] from O'Reilly. Great book, great language.

    On a shameless side note, if you're a Scrabble fan, come check out my online, multiplayer Scrabble program written in Python. PyScrabble [sf.net]
  • by YA_Python_dev (885173) on Wednesday January 11, 2006 @04:11PM (#14448344) Journal
    On the python.org [python.org] site you can find a big list of Python books [python.org].

    I suggest:

    Good reading.

  • Re:python regexes (Score:3, Informative)

    by Just Some Guy (3352) <kirk+slashdot@strauser.com> on Wednesday January 11, 2006 @04:38PM (#14448583) Homepage Journal
    What part of Python's regexps did you not like? The main difference I was was that instead of:
    if ($var =~ /some?pattern*/) { foo }
    you'd write something like
    if re.search('some?pattern*', var): foo
    or if you're doing the same match many times:
    pattern = re.compile('some?pattern*')
    if pattern.search(var): foo
    (kind of like Perl's "/o" once-only modifier).

    So, the calling convention is slightly different - one is procedural, and one is OO - but Python uses Perl's regexp engine so the patterns themselves should be identical.

  • I started with Perl (Score:2, Informative)

    by PerlPunk (548551) on Wednesday January 11, 2006 @04:48PM (#14448675) Homepage Journal
    Since the start of the review is basically a flame against Perl, I can't resist making a plug for it--especially since it was the first serious programming language that I learned.

    If a programming language is sufficiently powerful, you won't become proficient in it overnight. For myself, I went through three stages: tutorial, hobby, profession.

    It started with me back in 1999 when I wanted to learn HTML, and so I set out to learn it. But in the mean time, a friend of mine in the business told me that with Perl you could pretty much do anything you want in making web applications. At the time, I didn't know the difference between server-side and client-side scripting, and I figured, why not give it a try?

    So I searched on the internet and found Robert's Perl Tutorial. The introduction says, "It assumes that the reader knows nothing of programming whatsoever. . ." On reading it, I knew this was for me. So, eventually I found out I had to download Perl, which I did, and then I started going through the tutorial. URL: http://www.sthomas.net/oldpages/roberts-perl-tutor ial.htm [sthomas.net]

    Going through the tutorial took me two or three weeks. After finishing it, I decided to try to make my nascient website cooler than it was by adding some server-side scripting. Now that I wasn't just in the tutorial anymore, I had to learn something about CGI. That's when I found the site "CGI Programming 101", http://www.cgi101.com/class/ [cgi101.com] (I'm pleased it is still around, too.) From this I learned the rudiments of CGI programming with Perl.

    From this, I wrote a program called Article Master, which, had I stuck with developing it, could have been *the* killer-app blogging software instead of MovableType. (I'm sure there are probably 50,000 other geeks out there who also started out with something like this, discontinued development on it, and are still kicking themselves in the butt for missing out on coming out with the killer app.) In any case, after building the software and getting it to work kind of OK, I developed a deployment package for it and submitted it to an online Perl script archive. After submitting it, the archive gave me a free email address and access to the exclusive programming forums. The site sent me an email telling me I got these exclusive benefits because I was a programmer.

    I had never thought of myself as a programmer, but here was a site brimming with programmers telling me I was one of them. It was such a positive boost for me that it encouraged me further to develop my skills.

    Soon enough, I bought the Perl CD Bookshelf from O'Reily. Now, I had all the information and reference material I needed to write almost anything I wanted. I did some other personal online projects, and then, somehow I got the idea to try out getting a job using Perl. (This was at the beginning of 2000, just before the dot-com bust, so the entrance bar was set pretty low.) I called up a head-hunting agency and asked them if they needed someone who knew Perl. The agent on the other side said, "Get down here ASAP!" I went, I took their computerized test, and the results made him do backflips. (Hey, I knew what JAPH meant, and that was a question on the test!) He said he would have no problem getting me into a job, which he did. (And the money was more than I had ever dreamed of making.)

    When I started, I got an assignment (all CGI development) from one of the other lead programmers, and he asked me how long the job might take me. I hesitated, and just before I was about to say "a few days", he asked if I could do this in a few hours. I said, "Yeah, OK." I asked him if there was an HTML tool they used, and I just got this blank stare. I learned quickly that real Perl programmers don't use HTML editors--like our Perl code, we type everything else by hand. I somehow rose to the occaision and got the job done in time. From t
  • Re:Perl vs. Python (Score:3, Informative)

    by JoaquinFerrero (524609) on Wednesday January 11, 2006 @04:57PM (#14448760)
    Why? You can write Perl & Python together:
    #!/usr/bin/perl

    use Inline Python => <<'END_OF_PYTHON_CODE';
    def add(x,y):
    return x + y

    def subtract(x,y):
    return x - y

    END_OF_PYTHON_CODE

    print "9 + 16 = ", add(9, 16), "\n";
    print "9 - 16 = ", subtract(9, 16), "\n";
  • by jaydonnell (648194) on Wednesday January 11, 2006 @05:32PM (#14449085) Homepage
    yes and no. I use python and ruby at work and I prefer ruby as a language. Python does have better support and more mature libraries and it's a very nice language. We have a mix of linux and windows and python has much better windows support which is why we still use it as much as we do. The docs issue is weird. Ruby doesn't have as many docs, but I feel the docs they do have are often better (this is probably just personal preference). The python docs have left me wanting many many times. They are there for sure, but they can be really lacking.

    Also, python does not have real threading support. It has the GIL which will prevent your threaded python app from using more than one processor, but it's still better than ruby's thread support. I don't think this is much of an issue for two reasons.
    First, a lot of threaded apps are threaded because they are waiting on io of some sort usually network io. Ruby and python both work perfectly well for this type of threading need.
    Second, I've only ever done one project that needed to be multithreaded so it's a non factor for me and I think most people are in the same boat.
  • by McKing (1017) on Wednesday January 11, 2006 @05:52PM (#14449280) Homepage
    Objects!

    Perl == horrible bolted-on afterthought OO

    Python == *much* better (real objects, finally!)

    Ruby == pure heaven, everything is an object and iterable by default.

    I was bored one day at home and recreated a class in ruby that I wrote at work in perl. Took me all day to do something in perl that it took about 1/2 an hour to do in ruby, and I added a couple of features as well. I also spent way more time looking up how to do stuff in perl that in ruby, event though I've programmed off and on in perl for years (a decade, in fact)....
  • by ExoticMandibles (582264) on Wednesday January 11, 2006 @06:06PM (#14449388)
    Thanks for reposting that. No thanks for removing the attribution--I wrote that, back in 1999. And I have proof. [netfunny.com]

    larry

  • by Just Some Guy (3352) <kirk+slashdot@strauser.com> on Wednesday January 11, 2006 @06:46PM (#14449747) Homepage Journal
    Ummm, Dude? Python is not strongly typed.

    Ummm, Dude, yes [wikipedia.org] it [diveintopython.org] does [artima.com].

    Guido seemed to be discussing dynamic versus static typing, not weak vs. strong.

  • Re:being python (Score:2, Informative)

    by Zencyde (850968) <Zencyde@gmail.com> on Wednesday January 11, 2006 @07:40PM (#14450108)
    One of the programs associated with Python is called Idle (used for typing code and then running without any compiling, good for quick tests), this name comes from Eric Idle, who was on the cast of Monty Python.
  • Re:being python (Score:2, Informative)

    by Ksevio (865461) on Thursday January 12, 2006 @12:43AM (#14451627) Homepage
    The language was actually named that because of Monty Python so that's not far off: http://python.org/doc/faq/general.html#why-is-it-c alled-python [python.org]

The last person that quit or was fired will be held responsible for everything that goes wrong -- until the next person quits or is fired.

Working...