Slashdot Mirror


The Python Cookbook

Nice2Cats writes "Python is something of a programmer's dream and an author's nightmare. What started life as a scripting tool for the Amoeba operating system has matured into a full-blown programming language with such speed that every book seems to be outdated in a year or two. To make matters worse for publishers, the crew around Python's creator Guido van Rossum keeps adding higher-level constructs such as iterators with every new release, reducing reams of code to single-line idioms at half-year intervals. Because not everybody has been able to keep up -- RedHat 7.3 infamously still ships with version 1.5.2 as the default, while SuSE 8.0 is hanging in there with version 2.2 -- authors are forced to cover stone age variants as well as modern forms. Python is cross-platform (Unix/Linux, Mac, Microsoft), has two underlying languages (C for Python, Java for Jython) and works with various GUIs (Tkinter, wxWindows, Qt, GTK, curses, Swing). Given this breadth of material, the idea of writing that most fragmented form of a programming book, a 'Cookbook,' seems as crazy as, say, nailing a dead parrot to its perch." Read Nice2Cats's review below of The Python Cookbook to see how well O'Reilly deals with dead parrots. The Python Cookbook author Alex Martelli and David Ascher pages 574 publisher O'Reilly rating 8 reviewer Nice2Cats ISBN 0596001673 summary A recommended book for the language with no Slashdot icon.

Beautiful plumage. O'Reilly, fortunately, has all kinds of experience with animals.

The Python Cookbook consists of seventeen chapters that contain between eight and twenty-six individual recipes. Chapters and recipes are roughly ordered by increasing complexity, length, and required background knowledge, starting with the simple "Swapping Values Without Using a Temporary Variable" and ending with the complete module "Parsing a String into a Date/Time Object Portably." The chapters are mostly organized by subject -- "Text," "Files," "Object-Orientated Programming," "User Interfaces" -- but also include "Python Shortcuts" and "System Administration." The background required varies: Whereas the chapter on "Text" starts off with Fred L. Drake reviewing the most basic string operations such as slicing and concatenation, Paul F. Dubois can only sketch the core concepts of lexing and parsing in "Programs About Programs."

This of course is a hallmark of all cookbooks, programming- or food-wise: Nobody will like everything, but everybody will like something. The worst fragmentation occurs, as expected, between examples of Python 1.5.2 and Python 2.2. Most recipes give preference to one version, and then point out how the problem could have been solved in the other version. This is more useful than the code that was written for all versions, because it gives a deeper insight into the changes that Python has gone through. The result is that after a few chapters, you start wondering why anybody in their right mind would keep using Python 1.5.2 instead of 2.2.* with its iterators, list comprehensions, new classes, and expanded module library.

Martelli and Ascher have done a good job balancing the different forms. Only one chapter struck me as lopsided: "System Administration", where ten of the sixteen recipes are Windows-only. Even though there is a good reason for this -- Microsoft's native administration tools just aren't like those provided with Unix -- the editors might want to rethink the selection of recipes in this chapter for future editions.

Generally helpful. The "Python Cookbook" has helped me in three ways. First, I found quite a lot of the examples themselves, especially those in the chapters "Python Shortcuts" and "Object-Orientated Programming" useful for everyday work. Second, reading more than 500 pages of peer-reviewed and well-commented code gave me a greater feeling for common idioms and constructs that are rare in this clarity in wild-type code. However, the book is strongest when more general principles of "Pythonic" programming are discussed, for example when Martelli demonstrates the merits of the "Look Before You Leap," "Easier to Ask Forgiveness than Permission," and "Homogenize Different Cases" methods.

My favorite recipe is Sebastien Keim's "Implementing a Ring Buffer," where an object carries a class deep in its bowels, and changes into this class in a rather cool Dr.-Jekyll-to-Mr.-Hyde transformation on the fly. The one recipe I found downright evil was "Sending HTML Mail," which should have been implemented as "Turning HTML Mail into Plain Text" with a note on how people who send HTML mail are going to be the first against the wall when the revolution comes. The best quote in the book comes from Tim Peters: "We read Knuth so you don't have to" -- Python's promise of programming power for the people, expressed in (dare I say it) a nutshell.

Conclusion:

I can recommend the "Python Cookbook" wholeheartedly to anyone who has passed into the advanced stage of language learning and is willing to actually sit down and work through the code. Anybody who is looking for a deeper understanding of Python, solutions to common coding problems, or starting points for their own projects will also profit. This book should have RedHat customers hammering at the gates of Raleigh, demanding the power of iterators and list comprehensions that their SuSE counterparts already enjoy by default; it demonstrates the superiority of Python 2.2.* over 1.5.2 in great detail.

Because of this, however, my guess is that 2.2.* will quickly replace 1.5.2, turning large parts of this book into historical footnotes in two years at the latest. This is no fault of O'Reilly's, but rather a current fact of Python life. The editors have done a good job of nailing the parrot, and until this Pythonic Norwegian Blue does the inevitable backflip, it should give its owner much pleasure.

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

221 comments

  1. They don't eat pythons, do they? by Darth+RadaR · · Score: 5, Funny

    The title "Python Cookbook" has gotta look weird to people bopping around Barnes & Noble who aren't in the know. :)

    --
    /*drunk.. fix later*/
    1. Re:They don't eat pythons, do they? by wirefarm · · Score: 5, Funny

      I was at a bookstore years ago and this old preacher-type guy came up to me and started saying how pleased he was to see a young guy like me interested in religion -

      I didn't have the heart to tell the guy exactly what "Linux Bible, the Gnu Testament" was about...

      (Then again, I probably do as much preaching about Linux as he does about God - maybe we should get it declared a religion and get tax-free status...)

      Cheers,
      Jim in Tokyo

      --
      -- My Weblog.
    2. Re:They don't eat pythons, do they? by Anonymous Coward · · Score: 0

      maybe we should get it declared a religion and get tax-free status

      There's always Discordianism.

    3. Re:They don't eat pythons, do they? by Anonymous Coward · · Score: 0

      maybe we should get it declared a religion

      Nice... A religion where abstinence isn't required of its practitioners, but is thrust upon them due to their pear-shaped bodies and acne-riddled faces.

    4. Re:They don't eat pythons, do they? by Tablizer · · Score: 1

      Then again, I probably do as much preaching about Linux as he does about God

      You mean they are NOT the same?

    5. Re:They don't eat pythons, do they? by robocord · · Score: 1

      The worst title I ever saw like this is "Understanding SOAP." Admittedly, there are more than a few programmers that need this book under either of its possible meanings, but it still got me some odd looks when I was buying it.

    6. Re:They don't eat pythons, do they? by Anonymous Coward · · Score: 0

      'bout time Monty Python came out with a cookbook. I was getting tired of making all those dishes from my Northern Exposure cookbook.

      Always enjoy trying something new.

    7. Re:They don't eat pythons, do they? by Nailer · · Score: 2

      (Then again, I probably do as much preaching about Linux as he does about God - maybe we should get it declared a religion and get tax-free status...)

      Hey, it worked for Scientology ;)

    8. Re:They don't eat pythons, do they? by whereiswaldo · · Score: 1

      Hey, it worked for Scientology ;)

      I have heard only bad things about that religion. Movie stars need only apply.

    9. Re:They don't eat pythons, do they? by Anonymous Coward · · Score: 0

      There is no debate that Linux exists. And nobody thinks that Linux is all-powerful.

  2. Alternative Cookbooks by WIAKywbfatw · · Score: 4, Funny

    And for those of you that can't get your hands on a python, the adder, asp, boa, cobra, diamondback, etc cookbooks are just as well packed with tasty recipes.

    --

    "Accept that some days you are the pigeon, and some days you are the statue." - David Brent, Wernham Hogg
    1. Re:Alternative Cookbooks by sielwolf · · Score: 5, Funny

      Huh, I looked on O'Reilly's website and I couldn't find the ASP or Corba Cookbooks any- oh wait...

      --
      What is music when you despise all sound?
    2. Re:Alternative Cookbooks by shadow303 · · Score: 1

      Bah... just substitute chicken and it will taste the same.

      --
      I've got a mind like a steel trap - it's got an animal's foot stuck in it.
  3. Darn... by Kierthos · · Score: 2, Funny

    And here I was hoping for the recipe for crunchy frog.

    Kierthos

    --
    Mr. Hu is not a ninja.
    1. Re:Darn... by PONA-Boy · · Score: 0, Offtopic

      Oy!

      'Twould be more delectable with Ram's Bladder Cup!

      -PONA-

      --
      +that's funny...I don't FEEL tardy.+
  4. Python cookbook by gowen · · Score: 2, Funny
    As Mrs Beeton might have written: First catch your python

    Or, as Homer might add: "...mmm...python"

    --
    Athletic Scholarships to universities make as much sense as academic scholarships to sports teams.
  5. Not sure about cooking up a Python, but... by qurob · · Score: 5, Funny


    Cornmeal Crusted Rattle Snake with Cactus-Corn Succotash

    Recipe courtesy Joey Altman, Copyright 2001

    2 1/2 pounds rattle snake, dead
    1 cup buttermilk
    1 cup cornmeal
    1 cup flour
    1 tablespoon salt
    1 tablespoon chile powder
    1 tablespoon garlic powder
    1 tablespoon paprika
    1 teaspoon cayenne pepper
    1 teaspoon ground cumin
    1 cup vegetable oil
    Cactus-Corn Succotash, recipe follows
    Using a sharp boning knife remove the meat from the snake by cutting down the back, just slightly to 1 side of the spine from the head to the rattle. Using the tip of the knife peel the meat from the ?rib cage?. Once you removed the 2 long strips of meat, lightly pound them with the back of the knife to tenderize them. Cut the strips of meat into 1-inch pieces and place in a bowl with the buttermilk. Mix to coat well. In a large bowl combine the cornmeal with the flour and the spices. Heat the oil in a large skillet on medium high heat. Dredge the snake pieces in the flour mixture and fry for 2 minutes or until golden brown and then transfer to a paper towel lined plate. Repeat until all the snake pieces are cooked. Serve with Cactus-Corn Succotash.

    Cactus-corn succotash:

    2 tablespoons olive oil
    1 cactus pad, thorns scraped off, cut into small dice
    2 ears corn, shucked
    1 red onion, peeled, sliced in rings, grilled with olive oil and chopped in small dice
    1 bunch scallions, grilled and chopped
    1 chayote squash, sliced 1/4-inch thick, grilled with olive oil and chopped in small dice
    1 tablespoon minced garlic
    2 tablespoons minced jalape?o
    1/2 cup diced red bell pepper
    4 tablespoons butter
    1 cup chicken stock
    1 cup diced, peeled and seeded tomatoes
    1/2 cup chopped cilantro
    Salt and pepper

    Grilling the vegetables first gives another great layer of flavor, however, it is not absolutely necessary. Just omit that step and cook the vegetable right in the pan. In a skillet on high heat saute the vegetables except the tomatoes in the olive oil for 2 minutes. Add the stock and butter and cook until mixture reduces by half. Add tomatoes and seasoning and serve with the warm snake ?nuggets? on top.

    Yield: 4 servings
    Prep Time: 30 minutes
    Cook Time: 10 minutes
    Difficulty: Medium

    1. Re:Not sure about cooking up a Python, but... by cjsnell · · Score: 2


      Gotta love the New-York-attorney-goes-to-the-dude-ranch sound of "Cactus-Corn Succotash". You find this sort of crap at upscale eateries in places like Aspen and Telluride. This recipe is proof that any mediocre ingredient can be dressed up enough to taste good. I've had cactus and rattlesnake. While both are edible, I'd rather have Cornmeal-crusted Amberjack with a Roasted Polenta Succotash any day.

    2. Re:Not sure about cooking up a Python, but... by purrpurrpussy · · Score: 1

      Score:6 MMMmmm... Rattle snake...

      --
      "None of this shit works" -W.Shatner
    3. Re:Not sure about cooking up a Python, but... by BlackBolt · · Score: 2, Funny
      The best part of the recipe is of course
      2 1/2 pounds rattle snake, dead
      Dead? I was planning on having 2 1/2 pounds of LIVE rattlesnake roaming around my kitchen. Of course, if the snakes were still alive, I don't think they could honestly give this recipe a
      Difficulty: Medium
      I would hope for at least
      Difficulty: Fatal
      But for me, Kraft Dinner is almost fatal.

      BlackBolt

  6. Might actually be an interesting book to check out by Clockwurk · · Score: 0

    Python is implemented in QuArK (Quake Army Knife, a quake engine mapping tool) and is supposed to be quite useful in automating tedious procedures. Definately have to give it a look-see next time I'm at B&N

  7. I love python by paRcat · · Score: 3, Insightful

    There are those out there that hate any language that allows spaces to effect it's running...

    But Python just rocks. Throw pySQL, wxPython and Twisted into the mix, and you can have a full blown server with gui front-end that is just as stable as any other. I have a server that I wrote for wireless devices performing a few hundred SQL queries/changes and file writes per hour, and the speed is surprisingly very good for a language most people refer to as a 'script'.

    Not to mention, the tab requirement makes reading the code so easy. You just know where functions begin and end without having to deal with {'s and }'s.

    1. Re:I love python by CBackSlash · · Score: 1
      I have a server that I wrote for wireless devices performing a few hundred SQL queries/changes and file writes per hour, and the speed is surprisingly very good for a language most people refer to as a 'script'.

      I would certainly hope so.

      I think that even VB+Access on a 386 can manage that.

    2. Re:I love python by TV-SET · · Score: 1
      I have a server that I wrote for wireless devices performing a few hundred SQL queries/changes and file writes per hour, and the speed is surprisingly very good for a language most people refer to as a 'script'.

      Few hundred requests per hour? There are 3600 seconds in an hour. Even if you will have a thousand (vs few hundreds) requests, you will still have 3.6 seconds to complete it, which is a hell a lot of time, considering the nature of most requests and today's computers... damn, even yesterdays :)

      It is also pretty hard to see the speed difference, when you are talking about few hundreds queries and seconds, until, of course, you use a proper benchmark.

      I beleive you will see exactly the same speed with any other language. :)

      Not to mention, the tab requirement makes reading the code so easy. You just know where functions begin and end without having to deal with {'s and }'s.

      Tabs can be as easily used in most of the languages to improve readability. On the other hand, locating a missing/extra tab can be extremely painful, since your code can still run, but produce incorrect results.

      --
      Leonid Mamtchenkov ...i don't need your civil war...
    3. Re:I love python by Theom · · Score: 0

      It is equaly easy to misplace a }.

      --

      mp3: l33t term for empty.
    4. Re:I love python by Anonymous Coward · · Score: 0

      *BZZZT*

      try again. Blank lines terminate loops IN THE INTERACTIVE INTERPRETER. When actually running a program, blank lines in the middle of programs are perfectly acceptable.

    5. Re:I love python by William+Tanksley · · Score: 2

      Equally easy to misplace a }, as you mention; and much less visible.

      -Billy

    6. Re:I love python by Anonymous Coward · · Score: 0

      a curly brace '}' is less visible than a tab?

      You have got to be kidding.

      See if you can spot the tab on this page

    7. Re:I love python by Xtifr · · Score: 2

      But my editor will make it obvious when I misplace a }, as the indenting will automatically change. That is one thing I definitely miss when working with python -- the feedback I get from my editor is missing, which means I have to manually verify all of the indentation, and make sure it does what I want/mean.

      In practice, this proves to be a smaller problem than I originally expected (especially with good python bindings for my editor), and python is a beautiful language despite this minor wart, but I still consider it a problem with the language.

    8. Re:I love python by wormbin · · Score: 1

      I've written several large python programs and I enjoy the syntax as well. After programming in perl, java, C++ or some other language for a few days and then returning to python, I'm always shocked that I don't have to enclose all my if expressions in parentheses or end all of my statements with a semi-colon. If anyone has given python a serious shot (written a medium sized program) then they have to notice this ellegance.

      BUT...

      Everytime I have to add an outer block to two or more nested inner blocks...I cringe. After adding the outer block I have to carefully indent all of the inner blocks to make sure that I don't change the meaning of the program. With any of the curly brace languages I just add the outer block and C+M+/ (emacs) to re-indent the code.

      Has anyone gotten around this annoying, error-generating problem in python?

    9. Re:I love python by some+guy+I+know · · Score: 1

      The IDLE editor does Python autoindenting for you.
      (Of course, it's no vim...)

      --
      Those who sacrifice security to condemn liberty deserve to repeat history or something. - Benjamin Santayana
    10. Re:I love python by some+guy+I+know · · Score: 1

      If you are using IDLE to edit your source, select the entire block that you want to indent/outdent, then type CTRL+] or CTRL+[.

      If you are using vi (or vim or gvim), navigate to the end of the block, and type mz (mark location in register "z").
      Navigate back to the beginning of the block and type <'z or >'z.

      --
      Those who sacrifice security to condemn liberty deserve to repeat history or something. - Benjamin Santayana
    11. Re:I love python by wormbin · · Score: 1

      It looks like emacs also has this region indenting/unindenting with C-c < and C-c > Problem solved by having me RTFM. Thanks for the help!

  8. Debian also has 2.2 by psgalbraith · · Score: 3, Informative

    RedHat 7.3 infamously still ships with version 1.5.2 as the default, while SuSE 8.0 is hanging in there with version 2.2

    Debian unstable also has 2.2 as the default python, although the stable release has 2.1. But with the huge number of packages which depend on it, it takes a while to migrate all of them. So testing still has 2.1.

    1. Re:Debian also has 2.2 by Anonymous Coward · · Score: 0

      Actually, the current stable release of debian comes with 2.2.1 also.

    2. Re:Debian also has 2.2 by InodoroPereyra · · Score: 2

      And according to rpmfind.net, RedHat 8.0 too, and I can tell Mandrake 9.0 does (and 8.2 did), and the list goes on ... but yes, I never understood why RH 7.3 would ship Python1.52. They actually use python a lot for their config tools (which I consider a smart decision). Anyways ...

    3. Re:Debian also has 2.2 by tylerdave · · Score: 1

      I may be wrong but I'm pretty sure that the Python license wasn't GPL-compatible in the early 2.x versions. Becasue of this distros shipped w/ 1.52 (the lastest GPL-compatible version at the time). Python used a GPL-compatible license for 2.1 and later though so it shouldn't be an issue anymore.

    4. Re:Debian also has 2.2 by Ian+Bicking · · Score: 2
      Their tools depended on Python 1.5.2. Which would be fine if they had just used #!/usr/bin/python1.5 at the top of their scripts.

      The real problem was they used #!/usr/bin/python , and if you wanted to use a more modern Python as the system python (i.e., named simply "python") then you'd break system scripts. It's never been a problem otherwise to have two different versions of Python installed.

    5. Re:Debian also has 2.2 by rolfpal · · Score: 1

      I run redhat 8.0

      When I type "python"

      I get -

      Python 2.2.1 (#1, Aug 30 2002, 12:15:30)
      [GCC 3.2 20020822 (Red Hat Linux Rawhide 3.2-4)] on linux2
      Type "help", "copyright", "credits" or "license" for more information.

      Cheers,

      --
      nothing is real
    6. Re:Debian also has 2.2 by axxackall · · Score: 1
      I guess all software, which depends on Python 1.5, is dead in terms that no one update it anymore (otherwise - why not update the first line?). Red Hat people should forget about being lazy and change first line in all such obsolete stuff.

      That's not a big deal to create a script, which will go through all filesystem, find all "#!/usr/bin/python", change them to #!/usr/bin/python1.5. Once it's done - install Python 2.2 as defult python.

      Untill it's done - I am moving to Gentoo. Well, I begin to love Gentoo and I may stay with it anyway :)

      --

      Less is more !
    7. Re:Debian also has 2.2 by axxackall · · Score: 1

      By the way, alternately, Python people may forget about being lazy and keep better backward compatibility of the interpreter. Python is used now around the world for serious stuff - let's stop experiments (even I like new stuff in 2.2) and let's think about users!

      --

      Less is more !
  9. how well O'Reilly deals with dead parrots by wiredog · · Score: 2
    Here's the answer to that one.


    Parrot is a new, dynamic programming language, intended to merge the indubitable strengths of the twin Open Source scripting giants, Perl and Python. Stemming from the Open Source conferences, and culminating in the unprecedented meeting of minds at the new ActiveState Technical Advisory Board, Parrot was conceived jointly by Larry Wall, the original creator of Perl, and Guido van Rossum, the inventor of Python. By uniting the unparalleled flexibility of Perl with the simplicity and maintainability of Python, Parrot is destined to become the premier application development language of the twenty-first century.
    1. Re:how well O'Reilly deals with dead parrots by Elian · · Score: 1

      Yeah, but that parrot is actually alive and well, and doing nicely thanks. :)

    2. Re:how well O'Reilly deals with dead parrots by paco+verde · · Score: 1

      And the press release which includes a great interview with Larry and Guido.

      (For those a little slow on the uptake, check the date on the press release before you run out and buy the book)

  10. asdf by Chundra · · Score: 0, Flamebait

    This book should have RedHat customers hammering at the gates of Raleigh, demanding the power of iterators and list comprehensions that their SuSE counterparts already enjoy by default; it demonstrates the superiority of Python 2.2.* over 1.5.2 in great detail.

    I've been seeing a lot of complete shit like this lately. What ever happened to compiling it? Jesus. It might make your review seem a bit more credible if you said "despite all the new stuff that keeps appearing in python, their online documentation is excellent so be sure to download the newest version at www.python.org". Or something. Nah...you have to turn it into some kind of distro bashing.

    1. Re:asdf by Phoukka · · Score: 4, Informative

      Much more to the point, Red Hat 7.3 has 1.5.2 as "python", but has 2.1 (IIRC) as "python2". And Red Hat 8 has 2.2.1 as its "python". And, as you said, it is eminently possible to download and compile the latest version, though you do have to be careful that you link in 2.2.x as "python2" rather than "python" on Red Hat 7.3, or many of the system apps break (up2date comes to mind...).

    2. Re:asdf by lunenburg · · Score: 2

      Come on, you know it's not a Slashdot story without a ignorant jab at Red Hat! It's the new trendy thing to do!

  11. Swapping Values Without Using a Temporary Variable by SloppyElvis · · Score: 2, Offtopic

    I have to ask (given my Python illiteracy), does Python have built-ins for such an operation? Or is this just "how to implement an old trick" to "get your feet wet" with Python?

    If my coffee is working correctly this morning, I'd assert that any language with an XOR-assign could accomplish this feat (with the added restriction that the vars be of the same size, or operations are performed iteratively on byte pointers).

    Below is chapter 1 of my new C cookbook:

    A ^= B;
    B ^= A;
    A ^= B;

    Short chapter.

  12. Python Cookbook? by loconet · · Score: 2, Funny


    Pythons? I heard they taste like chicken!

    --
    [alk]
  13. No Slashdot icon! by wiredog · · Score: 5, Interesting
    Something must be done! I request, nay, demand, that the Fearsome Slashdot Cabal develop a Python Icon immediately!

    Some sort of snake, perhaps...

    1. Re:No Slashdot icon! by Anonymous Coward · · Score: 0

      Snake??? No. A can of SPAM. A Lumberjack, maybe. A circus tent with wings?

    2. Re:No Slashdot icon! by lamp77 · · Score: 1

      Mzake it yourself friend. maybe this?



      http://www.osdj.com/2000-10/img/python.jpg

    3. Re:No Slashdot icon! by Dr.+Smeegee · · Score: 1

      >> Some sort of snake, perhaps...

      Hmmmm... Your proposal intrigues me. Perhaps a snake with a parrot in it's stomach. Something like the Saint-Exuperey (sp?) rendering of a python with an elephant in it's gullet in "The Little Prince"?

    4. Re:No Slashdot icon! by Sloppy · · Score: 4, Interesting
      It's not just a Slashdot thing, either. Even outside the scope of Slashdot, Python surprisingly doesn't seem to have a logo or mascot or anything. You would think that over the years, some artisitic person would have drawn a cute (Tux-like cute, if you know what I mean) snake or something, and everyone would have latched onto it. But it hasn't happened. Oh sure, I have seen some snakes here and there, but none of them have been widely adopted.

      If someone pulls it off, they might become famous. ;-)

      --
      As copyright owner of this comment, I authorize everyone to defeat any technological measure which limits access to it.
    5. Re:No Slashdot icon! by RealAlaskan · · Score: 1
      You would think that over the years, some artisitic person would have drawn a cute (Tux-like cute, if you know what I mean) snake or something, ...

      I propose a Norwegian Blue Parrot. Dead. Nailed to a perch.

    6. Re:No Slashdot icon! by Anonymous Coward · · Score: 0

      Some sort of snake, perhaps

      How about a python?

    7. Re:No Slashdot icon! by Warlock48 · · Score: 1

      I vote for the best-known of all pythons!

    8. Re:No Slashdot icon! by Anonymous Coward · · Score: 0

      Wonder when if ever the copyright to the image expires; it would be a pretty good choice. (if only because it would have such a pleasant history)

  14. Re:Might actually be an interesting book to check by Anonymous Coward · · Score: 0

    Don't you mean QuArK is implemented in python?

    You twat.

  15. Perl comparisons by goombah99 · · Score: 3, Insightful
    What I would like to have would be a merger of the perl and python cook books. I know my own understanding of perl exploded when I discovered the perl cookbook. I am now convinced that understanding a languages idioms is the secret to fluency.

    It would be very instructive to me to be able to see how the two languages handle each other's idioms. I have my brain wrapped around perl and when I try to think in python I get frustrated cause things I think should be simple aren't. Of course the reverse would be true if I knew python better (I guess).

    At present I think my python programming is too formal, like someone who just learned say french trying to speak it and saying "To The beloved person who bore me onto this earth; please to be informed that I have translocated my corpus into the domicale that lies here" instead of just saying "mom, I'm home".

    --
    Some drink at the fountain of knowledge. Others just gargle.
    1. Re:Perl comparisons by snowbike · · Score: 2, Informative

      Check out Perl to Python Migration by Martin Brown. Sure, it isn't O'Reilly, and it doesn't have "cookbook" in the title, but I've found it a good start for the type of thing you are asking about.

    2. Re:Perl comparisons by goombah99 · · Score: 2, Insightful
      Have not read that one. However I have seen similar concepts on line like "python for perl programmers." And generally these are not filled with examples of pithy worked translations. THe cook book contains the true idioms of a language hence i'd like to see a true cookbook-cookbook cookoff.

      for example, consider an indexed sort. in both perl and python you could do this by writing a loop to add an index field to each value then sort it then loop to gather the ordered indices. The only difference is the loops and indexing and sorting would have different grammar.

      But in perl one would probably instead do a map-sort-map idiom on a single line operation. And in python I suspect there is probably some simmilar idiom using iterators.

      its the idioms, not the formal grmammar crossovers that are important to learning to learning a new language.

      --
      Some drink at the fountain of knowledge. Others just gargle.
    3. Re:Perl comparisons by some+guy+I+know · · Score: 1
      consider an indexed sort. in both perl and python ... in python I suspect there is probably some simmilar idiom using iterators

      In Python:
      >>> a = [ 1, 4, 7, 2, 9, 43, 8 ]
      >>> a
      [1, 4, 7, 2, 9, 43, 8]
      >>> a.sort(sortfunc)
      >>> a
      [43, 9, 8, 7, 4, 2, 1]
      You can also define a sort function:
      >>> a = [ 1, 4, 7, 2, 9, 43, 8 ]
      >>> def ltfunc(a, b):
      return [0, -1][a < b]

      >>> a.sort(ltfunc)
      >>> a
      [1, 2, 4, 7, 8, 9, 43]
      --
      Those who sacrifice security to condemn liberty deserve to repeat history or something. - Benjamin Santayana
  16. Re:Swapping Values Without Using a Temporary Varia by Anonymous Coward · · Score: 5, Informative

    a,b = b,a

  17. This is a fine book.... by nob · · Score: 3, Funny

    The perfect companion piece to Bake a Snake.

    --
    daed si luap
  18. Looks more like.... by Anonymous Coward · · Score: 0

    What a twisted conglomeration.

    It looks more like Monty Pyhon's Cookbook. Oih, did you say SPAM?? SPAM SPAM SPAM!!!

  19. Obligatory Monty python Hungrarian phrase book by goombah99 · · Score: 1

    My hovercraft is full of eels
    May I please fondle your bum

    --
    Some drink at the fountain of knowledge. Others just gargle.
  20. Re:Shitty moderation by ObitMan · · Score: 0

    thats ok, i got modded down for a spam reference.
    Moderators are so anxious to mod down that they forget to think first

    --
    Who run Barter Town?
  21. Re:Swapping Values Without Using a Temporary Varia by swingkid · · Score: 1, Offtopic

    Actually, this is an undefined behavior in c and c++, and you'd do well not to rely on it doing what you expect.

  22. 2.2 for RedHat by redfenix · · Score: 5, Informative

    This book should have RedHat customers hammering at the gates of Raleigh, demanding the power of iterators and list comprehensions that their SuSE counterparts already enjoy by default; it demonstrates the superiority of Python 2.2.* over 1.5.2 in great detail.

    Of course, installing a new version of Python in RedHat is pretty painless, download the rpm and install it. You can find them here.

    --
    "It's a very tangled subsystem." --Windows kernel guru
    1. Re:2.2 for RedHat by jasonkohles · · Score: 1

      Or you can just install the python2 package that comes with 7.3.

    2. Re:2.2 for RedHat by Anonymous Coward · · Score: 0

      Hopefully as RedHat updates their config scripts, they'll actually use something like #/usr/bin/python22 or #/usr/local/bin/python22 so that it don't matter to them what /usr/bin/python points to.

    3. Re:2.2 for RedHat by Linux_ho · · Score: 3, Informative

      RedHat 8.0 installs Python 2.2.1 by default.

      --
      include $sig;
      1;
    4. Re:2.2 for RedHat by disappear · · Score: 2

      Ah, but that was never the issue.

      The issue is that third-party packages depend on particular versions of Python, and you thus can't change the default version of Python between point releases.

      That is, when 7.0 was released, Python 1.5.2 was the clear choice, given how little Python 2.x code existed at that point. So for the entire 7.x series, Red Hat needed to stick with Python 1.5.x as the default version. Now with the 8.x series, Python 2.2.x is the default version.

      This is Red Hat's policy, and is quite sensible when you think about their userbase. They did a similar thing with Sendmail: 7.x used 8.11.x, even though 8.12 came out in the middle of the 7.x series, 7.2 and 7.3 both stuck with 8.11, because there were substantial changes with 8.12 (like no longer requiring that everything run as root...)

      The goal is to make transitions within a major release as painless as possible, not only for us dumb sysadmins but also for third-party software developers: anything built against 7.0 should ideally run against 7.3 without so much as a recompile. Less ideally, you shouldn't have to port it but just rebuild it.

    5. Re:2.2 for RedHat by Anonymous Coward · · Score: 0

      If 2.2 isn't backward-compatible with 1.5 code, it was a mistake not to require language version declarations in scripts.

    6. Re:2.2 for RedHat by disappear · · Score: 2

      Yeah, but for Red Hat to blame the customer (as they'd be doing: "Your scripts are the problem, not our distribution!") would be suicidal in the marketplace.

    7. Re:2.2 for RedHat by axxackall · · Score: 1

      The solution is to check 3rd party installed scripts and fix them right after installation. Something like applying a pacth for ports in FreeBSD.

      --

      Less is more !
  23. Try Ruby! by Hornsby · · Score: 5, Interesting

    I used to code in Python, and now I use Ruby in it's place. I've found it to be just as readable but more terse. It's also extremely consistent in the way that everything is an object. You can say things like

    5.times {|n| puts n}

    and all kinds of other crazy things. I'm not saying it's better than Python(not trying to start a flame war). I'm just saying to try it and see if you like it.

    --
    A musician without the RIAA, is like a fish without a bicycle.
    1. Re:Try Ruby! by Anonymous Coward · · Score: 0

      I'll ask the question: what does your code snippet do, anyway?

    2. Re:Try Ruby! by bwt · · Score: 2

      I certainly like Ruby, but I can't wait until parrot gets evolved enough so that Ruby and Python (and of course Perl) can all interoperate (and perform better to boot). Perl has absolutely huge collections of modules, but when you move to Python you give up some of them (Python has many equivalents, but not all). Moving to Ruby you give up even more. Why? We are triplicating our work. Everybody should compile to parrot.

      Compare Jython, which allows Python to use Java classes (and JRuby does the same for Ruby, but isn't as far along). This is a pretty powerful combination, but it suffers from the problem that Java isn't free software (free work-a-likes are slowly emerging, but aren't feature complete).

      I really think people should get excited about parrot. It has the potential to compete as a 100% open source solution with .net and java.

    3. Re:Try Ruby! by jonathan_ingram · · Score: 1

      Does Ruby still have the perl-style variable warts? I'll start looking at the language as soon as those go away.

    4. Re:Try Ruby! by raistlinthegreat · · Score: 1

      yes Ruby has some of this variables, but they
      are not used very often in Ruby.

      believe me, Ruby code looks much more readable than
      Perl code (unless you really want to mess up the code but this you can do in any language).

      since I have started using Ruby I use it always when I would have used perl before.

      you really should give it a try

    5. Re:Try Ruby! by fakane · · Score: 1

      > I'll ask the question: what does your code snippet do, anyway?

      % ruby -e '5.times {|n| puts n}'
      0
      1
      2
      3
      4

    6. Re:Try Ruby! by Twylite · · Score: 1, Insightful

      Looks like a classic example of bad syntax to me. I don't know Ruby, or Python ... but I do know when I see a language which does not have an intuitive syntax or grammar.

      While the "5.times" is rather obvious, if not leaving one wondering why a "." is needed, |n| would be read by your average degreed professional developer as "the absolute value of n", given its visual similarity to the well known and standard mathematical notation for this operation. Which of course makes "|n| puts n" a rather illogical statement, and a best "take the absolute value of n and then print it".

      Terse is good only if it is understandable ... not if it is readable.

      --
      i-name =twylite [http://public.xdi.org/=twylite], see idcommons.net
    7. Re:Try Ruby! by kelzer · · Score: 1

      Sorry to continue this off-topic (or is it tangential?) thread, but the construction {|parms| statements} is called a code block and comes straight from Smalltalk. That construction allows Smalltalk and Ruby to pass around code as an object. About 10 years ago, version 5.x of Clipper, a dBase compiler that still has a pretty big following, added code blocks using a similar syntax.

      --

      ---------------------------------------------
      SERENITY NOW!!!!!!!!!!!!!!!!
    8. Re:Try Ruby! by Hornsby · · Score: 4, Informative

      The "." is needed because 5 is an object of type Fixnum. times is a method available to Fixnum objects. I used that example to demonstrate that EVERYTHING in Ruby is an object. For instance, you can do the following:

      "hello world".upcase
      "HELLO WORLD"

      Not to mention method cascading

      "hello world".upcase.reverse
      "DLROW OLLEH"

      Once you get used to having these features, it's hard to go back(to Perl that is...). There are a number of other very nice features as well. Iterators for example(which Perl 6 is going to include).

      list = ["foo", "bar", "car"]
      list.each do |elem|
      # do something with elem
      end

      For a quick walkthrough of the languages features, go here: http://rubycentral.com/book/intro.html

      I do know when I see a language which does not have an intuitive syntax or grammar.

      And what language does? Any new language requires an adjustment period. The important thing is consistency once you get over the initial learning curve. Lisp doesn't necessarily have an intuitive syntax either; however, few would argue that it's not a powerful language. The consistency of having everything represented as a list makes it's syntax extremely simple.

      --
      A musician without the RIAA, is like a fish without a bicycle.
    9. Re:Try Ruby! by PommeFritz · · Score: 1

      Let's stick to Python:

      "method cascading":

      >>> 'HELLO THERE'.capitalize().swapcase()
      'hELLO THERE'

      iterators:

      mylist=['foo','bar','car']
      for item in mylist:
      # do something with item

      But it starts getting interesting when you start using the 'yield' statement (generators)...

    10. Re:Try Ruby! by Fweeky · · Score: 2
      iterators:

      mylist=['foo','bar','car']
      for item in mylist:
      # do something with item

      Iterators are an expression of a deeper construct in Ruby; passing code blocks to methods. Example:

      File.open('foo') do |file|
      # do some file operations
      # maybe raise some exceptions
      end # file is automatically closed the the File.open method

      But it starts getting interesting when you start using the 'yield' statement (generators)...

      Funnily enough, something Python grew after Ruby had been using it for years.
    11. Re:Try Ruby! by Fweeky · · Score: 2
      I do know when I see a language which does not have an intuitive syntax or grammar.

      Intuitive is highly subjective. Ruby comes from the perspective of objects and method calls and passing code blocks around.

      While the "5.times" is rather obvious, if not leaving one wondering why a "." is needed

      "times" is a message sent to the 5 object; a Fixnum instance. Ergo it is the same as:

      class Foo
      def times
      # some code
      end
      end

      i = Foo.new
      i.times

      The code block being passed to it (the {|i| .. }) is incidental, and seperate from the method call itself.

      |n| would be read by your average degreed professional developer as "the absolute value of n", given its visual similarity to the well known and standard mathematical notation for this operation

      That's a SmallTalk thing; Ruby chose to reuse it. Typical use is more like:

      [1,2,3,4].each do |i|
      # do something with i
      end

      It's also fairly common to see:

      {'a' => 1, 'b' => 2}.each do |key, value|
      # do something with hash element
      end

      I guess the alternative would be something like:

      hash.each do(key, value)
      # ...
      end

      But since you can also use braces, you'd then get:

      hash.each {(key,value) .. }

      Which looks a bit nasty to me.

      Anyway, it doesn't take much to work out what it means even if you've never seen SmallTalk and friends. People are very good at handling different meanings in different contexts.
    12. Re:Try Ruby! by Fweeky · · Score: 2
      Does Ruby still have the perl-style variable warts?

      Yes it does; they're very tame, and no, they're not going away:
      $foo = 'bla' # global variable (not seen much)
      @foo = 'bla' # object instance variable
      @@foo = 'bla' # class variable (not seen much)
      Most of the time you only see @foo, and you can hide them behind accessors and just use self.foo if you don't like them. Ala:

      class Foo
      attr :foo

      def initialize(bla)
      if (coder_hates_at?)
      self.foo = bla
      else
      @foo = bla
      end
      end
      end

      @foo bypasses the accessor 'attr' produces, so is a bit faster.

      The $1..$9, $_ etc vars are still there, but you don't have to use those either. They're sometimes handy writing quick scripts and oneliners.
    13. Re:Try Ruby! by Ian+Bicking · · Score: 2
      I think the reason people aren't getting excited about Parrot is that it hasn't had any significant progress. Skepticism among Python developers has been high (by Python developers I mean the people who work on writing the Python interpreter), and there's been criticism that work has been directed towards optimization before any real language can be targetted for Parrot.

      Parrot would be cool, but a free CLR might come around a lot faster.

      I'm also unclear also how languages with significantly different semantics will interact. Ruby and Python, for instance, could interact very easily, since they have similar semantics. But Perl, for instance, considers "12" and 12 to be pretty much equivalent. But when you have some function written in Python, and you pass a string instead of a number, you're likely to get an error (or worse). So now the Perl programmer has to be aware of the languages he's interacting with, which is part of what we were trying to avoid.

      It's a hard problem, and I don't know that it's easy to solve.

    14. Re:Try Ruby! by Fjord · · Score: 2

      I also fnd it mor rdbl but mor trs

      --
      -no broken link
    15. Re:Try Ruby! by HiThere · · Score: 2

      The grammar of FORTH is intuitive. The grammar of the early LISPs was also intuitive (before they started adding things like macros).

      Problem is, if you have a simple, intuitive, grammar, then you need to have lots of words that don't have a simple, intuitive, meaning. In FORTH a good example is " (i.e., the word signified by a double-quote). This needs to do some fancy manipulation, because the language doesn't understand anything but see-it, do-it. (An even better example is (COMPILE), but that requires knowing the guts of the language.)

      So, if I remember correctly, the FORTH hello-world program would be:
      " Hello, World" .
      The first " siezes the input stream until it encounters a ", and places the address of the stuff on the top of the stack. The period prints whatever the top of the stack is pointing at. (Period might be the wrong command here, though. Which command to use where has long slipped from my memory.)

      But the grammar is as simple and intuitive as possible.

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    16. Re:Try Ruby! by d_i_r_t_y · · Score: 1

      I think the reason people aren't getting excited about Parrot is that it hasn't had any significant progress.

      not true. a recent post to perlmonks and to slashdot announced that parrot is currently able to parse and run a large subset of perl6, as well as a subset of python, ruby, and can also do some interpretation of java .class files. this is hardly 'insignificant' progress...

      But Perl, for instance, considers "12" and 12 to be pretty much equivalent.

      that's also untrue -- in perl5, one could be forgiven for thinking that there is no semantic difference between strings and numbers, though there is, it's just hidden beneath a layer of DWIM-ery (do what i mean).

      in perl6/parrot however, there are discete types for strings, numbers, booleans, floats, named object types, etc. perl6 also has a declarative syntax to indicate type, eg:

      my int $expected_release = 2003;
      my str $lang_name = "perl6";

      hypothesise( $lang_name, $expected_release );

      sub hypothesise ( str $lang, int $year ) {
      print "$lang is expected to be out in $year";
      }

      so, ruby, python, and perl6 will not be so different after all, and your concerns about their interaction on type semantics grounds, are unfounded.

      IMO, parrot is an excellent concept, and its execution is coming along just fine, albeit not as fast as it could be. but good things take time.

      a language agnostic runtime for dynamic languages is a *fantastic idea* and benefits everyone who uses those languages.

      everything these days is gravitating towards higher and higher levels of abstraction these days; in the case of languages, it's in the form of virtual machines/runtimes. who wants the individually brilliant scripting languages to languish in fractured and bickering ego-groups against the .net and java (marketing) onslaught?

    17. Re:Try Ruby! by Anonymous Coward · · Score: 0

      Ruby is for losers, though.

      Everyone knows it.

  24. Re:Swapping Values Without Using a Temporary Varia by thomas.galvin · · Score: 2

    Ah, fond memories. I remember showing that to a friend a while ago. He looked at it all cross-eyed, then ran off to see if it actually worked. Five minutes and a "holy s**t!" later, I knew he got it.

    And there isn't anything wrong with implementing an old trick to get your feet wet in a new language. "Hello, world!" is a classic for a reason. When you are learning somethign new, any tie you can make with what you already know is helpful.

  25. Re:Swapping Values Without Using a Temporary Varia by spakka · · Score: 1, Informative

    No, it isn't.

  26. Re:Swapping Values Without Using a Temporary Varia by rpeppe · · Score: 1

    no it's not.
    it's only undefined when used like:

    a ^= b ^= a ^= b;

    (or whatever it usually is, i haven't memorised it 'cos it's wrong!)

    doesn't python have tuples, so you can do:

    (a, b) = (b, a);

    (caveat: i don't know python!)

  27. Re:Swapping Values Without Using a Temporary Varia by back_pages · · Score: 1

    If I may perpetuate the cliche, I looked at that cross-eyed, worked it out, and said, "Holy s..t!"

  28. Re:Swapping Values Without Using a Temporary Varia by gCGBD · · Score: 1

    $ python Python 2.0 (#1, Nov 5 2000, 21:13:18) [GCC 2.95.2 19991024 (release)] on sunos5 Type "copyright", "credits" or "license" for more information. >>> a='hello' >>> b='goodbye' >>> (a,b)=(b,a) >>> a 'goodbye' >>> b 'hello'

    --

    O=='=++
  29. Re:Swapping Values Without Using a Temporary Varia by gCGBD · · Score: 1

    Sorry - forgot to select "Text Formatted" for
    this cut and paste in my post from a minute
    ago ... (and danged if I'm going to convert
    all of those ">" to ">".

    $ python
    Python 2.0 (#1, Nov 5 2000, 21:13:18)
    [GCC 2.95.2 19991024 (release)] on sunos5
    Type "copyright", "credits" or "license" for more information.
    >>> a='hello'
    >>> b='goodbye'
    >>> (a,b)=(b,a)
    >>> a
    'goodbye'
    >>> b
    'hello'

    --

    O=='=++
  30. Re:Swapping Values Without Using a Temporary Varia by theMAGE · · Score: 1

    Bah, that's waay easier in Python:
    (a, b) = (b, a)

  31. Don't click on Slashdots book link by RedWolves2 · · Score: 0, Offtopic

    bn.com has this book listed for $31.96. Get it from Amazon for $27.97

    Save some money!

    1. Re:Don't click on Slashdots book link by Gramie2 · · Score: 2, Informative

      Or $24.50 from www.bookpool.com, which is almost always better than other online bookstores, although I'm not sure how it does once shipping is factored in.

  32. Re:Swapping Values Without Using a Temporary Varia by Azghoul · · Score: 1

    Bigger question: Who cares if you can swap values without using a temporary var? Is this important in some way?

    No really, I'm no CS major, I have no idea.

  33. Re:Perl comparisons - see PLEAC by Anonymous Coward · · Score: 1, Informative

    This is almost exactly what you want (assuming you have the Perl Cookbook in hand):

    http://pleac.sourceforge.net/pleac_python/t1.htm l

  34. Re:Might actually be an interesting book to check by AndrewHowe · · Score: 2

    No, he doesn't, although he could have worded it better.
    QuArK is not implemented in Python.
    Scripting is implemented in QuArK, using an embedded Python interpreter.
    Smack!

  35. Re:Swapping Values Without Using a Temporary Varia by shadow303 · · Score: 1

    It's not really a big deal, but looking for little tricks to deal with little problems is good practice and gets you used to trying to think of multiple ways to do something. Training yourself to attack a problem from multiple directions can be useful when trying to find a solution to a more difficult problem.

    --
    I've got a mind like a steel trap - it's got an animal's foot stuck in it.
  36. Church of Emacs by yerricde · · Score: 1

    I probably do as much preaching about Linux as he does about God - maybe we should get it declared a religion and get tax-free status

    There is already a so-called Church of Emacs. You don't want to dance with the devil.

    --
    Will I retire or break 10K?
  37. MOD PARENT UP by goombah99 · · Score: 1

    That is a great resource. Now one needs the inverese (perl version of python cookbook) and to roll them into one.

    --
    Some drink at the fountain of knowledge. Others just gargle.
  38. perl/python phrasebook by mcc · · Score: 5, Informative

    Try this site.. it's basically a "phrasebook" that shows common tasks being done in both perl and python. It's a great introduction to the language, and it helps a lot in terms of getting the python-idiom-y ways to do lots of commonthings embedded into your head.

    It isn't *very* long, and doesn't go too deep, and the formatting's not great, but it's a quick read, and if it doesn't fit your needs there's always that book Snowbike recommended.

    At present I think my python programming is too formal

    The catch about the funkiness of python's syntax is not that it demands formalism; it's just that it demands you will do only one thing per line. It's kind of hard to get yourself thinking this way, and it's really irritating to write code this way (i never write python without pining for a ?: construct, a single-line version of "except", or a less-crippled lambda construct).

    The thing is, though, that obeying python's rule basically comes down to seperating each expression into unnecessary variables, and mercilessly abstracting all those potentially-repeated 'common tasks' that somehow always seem to wind up taking five lines in python into functions. However, i find when i write perl, most of the time i spend revising code is spent going back and doing the above two things-- splitting overly-complex expressions into subvariables, pulling out bits of code and making them subexpressions. Python just forces you to do these things ahead of time, and you benefit greatly in the long run. (Whether that's worth all the irritation, though, i don't know :))

    1. Re:perl/python phrasebook by ameoba · · Score: 2

      The catch about the funkiness of python's syntax is not that it demands formalism; it's just that it demands you will do only one thing per line.
      -----------------

      counterexample:

      print (lambda A,D,B,C,E,F,G,H,Q:"\n".join(["".join([(Q[int(__imp ort__("math").log((reduce(lambda x,y:abs(x[1])<=D and (x[0]+1,x[1]**2+y[1]) or x,[(0,complex(r/B,i/B))]*A))[0]+1))%len(Q)]) for i in range(F*B,G*B,H)]) for r in range(C*B,E*B,H)]))(1500,4,100.0,-2.25,1.5,-1.25,1 .25,4,".^:/I&@*%$#")

      --
      my sig's at the bottom of the page.
    2. Re:perl/python phrasebook by steveha · · Score: 2

      it demands you will do only one thing per line. It's kind of hard to get yourself thinking this way

      No, I write code like that all the time.

      When single-stepping in the debugger, I really hate having multiple things happen in a single-step. It's so much nicer to be able to see things happen one step at a time.

      Back in the really bad old days, compilers might have been dumb enough that you would get worse code when you only did one thing per line, but that hasn't been true in a long time. Your single-statement lines will be folded by the compiler. With optimizations enabled, the compiler will generate the same code from

      x = foo();
      if (x)
      return;

      as from

      if (x = foo()) return;

      And I know which one I'd rather single-step.

      steveha

      --
      lf(1): it's like ls(1) but sorts filenames by extension, tersely
    3. Re:perl/python phrasebook by Anonymous Coward · · Score: 0

      Having to use a debugger at all is a sign that the code doesn't clearly express what it's going to do. Having to change your style to accomodate a debugger that can't even tell you which expression is about to be evaluated is going to make the code that much more work to read or maintain.

    4. Re:perl/python phrasebook by steveha · · Score: 3, Funny

      Thanks! You just made me laugh out loud, and that's always fun.

      Having to use a debugger at all is a sign that the code doesn't clearly express what it's going to do.

      No, it's a sign that the code isn't doing what you want it to do. Sometimes that's due to a flaw in your code. Sometimes it might even be due to something else, like an API call that doesn't do what you expect, or even an API call that is downright buggy.

      It's as silly to say that one should never need a debugger, as to say that one cannot do without a debugger.

      a debugger that can't even tell you which expression is about to be evaluated

      So, when you have a project on a platform with primitive development tools, what do you do? Refuse to work on the project?

      Tell me, what development tools do you use? They must be wonderful. Maybe I should use them.

      steveha

      --
      lf(1): it's like ls(1) but sorts filenames by extension, tersely
    5. Re:perl/python phrasebook by Anonymous Coward · · Score: 0

      That is the ugliest thing I have ever seen! I thought I knew Python pretty well, but what does that thing DO!?

    6. Re:perl/python phrasebook by Peter+Harris · · Score: 2

      Cool! A functional declaration for a close-up rear view of a goat. ;)

      --

      -- What do you need?
      -- Gnus. Lots of Gnus.
  39. Re:Swapping Values Without Using a Temporary Varia by swingkid · · Score: 2

    Yes, it is: look here

  40. Re:Swapping Values Without Using a Temporary Varia by Anonymous Coward · · Score: 0

    That doesn't say the behaviour is undefined. Just that it may not be as efficient as you think it is.

  41. Buying from evil companies by yerricde · · Score: 2, Insightful

    Get it from Amazon for [$3.99 cheaper]

    And fund enforcement of a patent that should never have been granted. If you want to preserve balance in the Force, you have to give to EFF every time you give to a company that employs "evil" practices with respect to statutory monopolies. That's why I don't buy more than $65 a year from Disney, Time Warner, Universal, or the other big nine copyright companies, and that's also why I don't buy from Amazon or use Unisys products.

    --
    Will I retire or break 10K?
  42. It had to be said by Torgo's+Pizza · · Score: 3, Funny
    Read Nice2Cats's review below of The Python Cookbook to see how well O'Reilly deals with dead parrots.

    No no he's not dead, he's, he's restin'! Remarkable bird, the Norwegian Blue, idn'it, ay? Beautiful plumage!

    1. Re:It had to be said by Anonymous Coward · · Score: 0

      No, it really didn't have to be said. At least, not in such an obvious fashion. Also: Moderators, this was not funny.

  43. Re:Swapping Values Without Using a Temporary Varia by AndrewHowe · · Score: 2

    I believe swingkid may be referring to the fact that if a and b are aliased to the same location in memory, the "trick" will go wrong (zeroing the value).
    But why would you swap something with itself?
    It would be almost impossible to achieve the aliasing in C, the only ways I can think of are:
    1) swap(a,a);
    2) union {int a; int b;} u;
    3) #define b a
    [or anything similar, i.e. int* b; b= swap(a,*b);]
    I would say that if you are swapping something with itself, you have a problem with your algorithm.

  44. Re:Swapping Values Without Using a Temporary Varia by PythonOrRuby · · Score: 2

    The parens aren't necessary. They are in Perl5, however.

  45. Language Development Speed by Bouncings · · Score: 4, Informative
    Actually, the rapid change in the language is pretty new. For the longest time, 1.5.x was stable, and years before 1.4.x was mostly the same. Then, 1.6 happened. Python hit some kind of critical mass where Guido decided to more or less open the flood gates of third party suggestions (called PEP's in Pythonlore). Another key factor was the rapid increase of XML libraries and concerns, as well as other quickly changing technologies.

    The author of this article doesn't mention it, but many Python programmers are upset with the rapid changes in the language, and it is very contrary to Python's history and philosophy. It looks like for now though, Python is slowing back down after implementing a new system of object orientation that really implements each variable/function/whatnot as an object. 2.2, hopefully, is here to stay for a while.

    --
    -- Ken Kinder ken@_nospam_kenkinder.com http://kenkinder.com/
    1. Re:Language Development Speed by Petronius · · Score: 1

      I find most of the new additions annoying. I think Guido & crew are adding these things to avoid people fleeing to other languages. Ruby comes to mind.
      It's too bad, I like Python mostly for its simplicity and elegance.

      --
      there's no place like ~
  46. Re:Python icon by TeknoHog · · Score: 5, Funny
    > If someone pulls it off, they might become famous. ;-)

    Yeah, like the guy who drew Tux, whatshisname..

    --
    Escher was the first MC and Giger invented the HR department.
  47. Perl Python by PythonOrRuby · · Score: 2

    In my own experience, I've experienced the opposite. I was pretty good at procedural programming, but the OO stuff always seemed rather intimidating.

    Then a friend twisted my arm and made me learn Python, and it wasn't necessarily that Python does OO well, but that it makes it really quick and easy to experiment. Doing so gave me sufficient understanding to go back into Perl and figure out how packages and modules and such work.

  48. Re:Swapping Values Without Using a Temporary Varia by spakka · · Score: 1
    I believe swingkid may be referring to the fact that if a and b are aliased to the same location in memory, the "trick" will go wrong

    I think it's more likely that (s)he's thinking of the a ^= b ^= a ^= b version, which is often touted as swapping a and b, but is undefined (modifies a twice between sequence points). This is an old chestnut on comp.lang.c which (s)he appears to read.

  49. 1.5.2 code still works with 2.2 by Anonymous Coward · · Score: 1, Insightful

    As demonstrated throughout the Cookbook all of the code snippets the code for 1.5.2 will work with 2.2. I think its unfair to say that the Cookbook will be deprecated or unusable in 2 years. The recipes are more than just code examples they explain the authors intent. As Python marches to world domination we will pick up interfaces, and a few other language features that will make it - the obvious general purpose language of choice. These features will not
    get in the way of people picking up the cookbook. Or make old code not work. It will
    merely make new code better.

  50. Re:Arghh Python by Rob+Riggs · · Score: 2

    Oh, blow it out your arse. Python is an object-oriented procedural language with some functional aspects thrown in for good measure. Python was never trying to be Lisp. And thank Guido for that!

    --
    the growth in cynicism and rebellion has not been without cause
  51. Re:Swapping Values Without Using a Temporary Varia by sql*kitten · · Score: 2

    a,b = b,a

    Pretty sure it works the same way in MATLAB, too, but I don't have mine here to check...

  52. Re:Swapping Values Without Using a Temporary Varia by Anonymous Coward · · Score: 0

    Why? The OP didn't write that version, (s)he put sequence points after each operation. And, the comp.lang.c article swingkid linked to said nothing about that at all (it has the sequence points too). The only things it did say were that it only works on integral types (but that should be a compile time check) and that it goes wrong if a and b are the same location in memory. Oh, and that the "trick" is useless if your processor has registers (it probably does...)
    - Andrew (going AC)

  53. Re:Swapping Values Without Using a Temporary Varia by rnbc · · Score: 1

    more concise: a^=b^=a^=b;

    --
    You cannot proceed from the informal to formal by formal means
  54. Cookbook? Well, what you got? by LoneWolf · · Score: 1

    Well, there's egg and bacon; egg, sausage and bacon; egg and spam; egg, bacon and spam; egg, bacon, sausage and spam; spam, bacon, sausage and spam; spam, egg, spam, spam, bacon and spam; spam, sausage, spam, spam, spam, bacon, spam, tomato and spam; spam, spam, spam, egg and spam; (Vikings start singing in background) spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam and spam.

    Or lobster thermador ecrovets with a bournaise sause, served in the purple salm Mr. Bunor with chalots and overshies, garnished with truffle pate, brandy, a fried egg on top and spam.

    [of course from Monty Python's SPAM Sketch]

  55. Re:Dead Parrot by Farmer+Jimbo · · Score: 1

    Heh, Dumb and Dumber. I actually paid money to see that in the theatre.

  56. HTML Email by DrSkwid · · Score: 2

    people who send HTML mail are going to be the first against the wall when the revolution comes.

    Congratualations on a thoroughly short-sighted viewpoint.

    HTML email is not just for spammers.

    The ability to send HTML forms to employees is a boon among other benefits.

    Maybe you've never shared the joy of sending an HTML birthday card to your child or parent.

    Perhaps sending A4 pngs around would be more to your liking?

    The ability to communicate with the richness of HTML expression should be embraced and standardised not spurned.

    aw, well. smash the HTML presses

    --
    There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
    1. Re:HTML Email by dvdeug · · Score: 3, Insightful

      HTML email is not just for spammers.

      No; it's also for people who want me to want a half hour to get my mail over my modem, so I can get the exact same message but with lots of HTML tags. (And invariablly lots of HTML tags - it never bears any resemblence to clean hand-written HTML.)

      The ability to send HTML forms to employees is a boon among other benefits.

      And what happens when you need to make a change to that form? Why not just stick it your own private webspace?

      Maybe you've never shared the joy of sending an HTML birthday card to your child or parent.

      Ah, yes; the wonderous feeling of "you crossed my mind, but I couldn't be bothered to walk to the store for a _real_ birthday card".

      It's a little more valid, but it's still something that can be done via web.

      The ability to communicate with the richness of HTML expression

      To be or not to be; that is the question. Whether 'tis greater to suffer the slings and arrows of outrageous fortunes, or by dying, end them. . . .

      I fail to see how this could be made richer by adding HTML. In general, just straight plain text is an extraordinarily powerful medium for communication. Frequently, HTML seems to be used as a means to doodle on the email, rather then add any information or emotional empact.

    2. Re:HTML Email by Anonymous Coward · · Score: 0

      one of the wonderful joys of HTML is hyperlinks. That form would do better as a hyperlink. So would the card, the hampster dance, and the vb macro virus. That said, I now see the need of HTML in email clients -- to include hyperlinks. Of course, then your email client would need to be able to launch a browser.

  57. No animal icon for Python... by SlowMovingTarget · · Score: 1

    Shouldn't it be a cartoon left foot, disembodied just above the ankle? You know like that one in the... Oh... Never mind.

    1. Re:No animal icon for Python... by Anonymous Coward · · Score: 0

      Yes the Monty Python intro Foot squishing a camel would be perfect.

  58. Egg Troll's view on Perl by egg+troll · · Score: 1

    Perl looks like an explosion in an ASCII factory.

    --

    C - A language that combines the speed of assembly with the ease of use of assembly.
  59. Re:Swapping Values Without Using a Temporary Varia by ameoba · · Score: 2

    too bad that only works on things that XOR makes sense for. What happens when you have lists of sockets? Or want to swap objects that aren't the same size?

    Tuple assignment is much more interesting, and, while showing "a,b=b,a" is trivial, showing how & where tuple assignment can be used is an important thing to pick up if you're comming from languages which don't allow such constructs.

    --
    my sig's at the bottom of the page.
  60. Slashdot topics by fm6 · · Score: 5, Insightful
    Slashdot icons are just designators for Slashdot topics, and these desperately need an overhaul. There are topics for companies that no longer exist (Digital, Compaq, LinuxCare; Be should probably be renamed "BeOS"); topics that are extremely low volume and should really be folded into other topics (Comdex, E+, Englightenment), topics that are just plain redundant (Bugs, Linux Business), topics that we need only because they're part of a more general topic we don't have (we have America Online, but no ISP topic; topics for various Desktops, but no general Desktop topic; topics for specific Linux distros, but no Distro topic). And why on earth do we have ten specialized Apple topics?

    Rather than a new topic for Python, I'd rather see a Scripting topic. So, yeah, that means no cute Python icon, but it does put all the scripting issues in one place for people to select or ignore.

    1. Re:Slashdot topics by elemental23 · · Score: 2

      Rather than a new topic for Python, I'd rather see a Scripting topic. So, yeah, that means no cute Python icon, but it does put all the scripting issues in one place for people to select or ignore.

      You mean like the current Developers section? True, it's a lot more than language related stories, but that's where you'll typically find them (except book reviews, which are usually in the Book Reviews section)

      You're welcome :)

      --
      I like my women like my coffee... pale and bitter.
    2. Re:Slashdot topics by theNeophile · · Score: 1
      And why on earth do we have ten specialized Apple topics?

      That's because we have a specialized apple section of slashdot. What, should every story on that page have the same generic apple icon?

  61. I abandoned Java for the same reason by goombah99 · · Score: 1
    After my first set of java 1.0 text went obsolete and then my second set of java 1.5 texts went obsolete, I realized that most of what I knew about java was obsolete. And I felt bewildered by all the new libraries and ways of doing things. The books I could buy around the time swing was coming out were a hodge podge of old and new ways of doing things. I decided to give up on java for at least 5 years. Maybe then it will shake out.

    --
    Some drink at the fountain of knowledge. Others just gargle.
    1. Re:I abandoned Java for the same reason by Anonymous Coward · · Score: 0

      That's ridiculous! Java has been the most consistent and clear language I've ever been involved with (C, ksh, Perl, Python, etc.)

      I've been working with Java since 1.0, and the only
      Java skills I've had obsoleted were the event handling changes between 1.0 and 1.1. Since then the core language has been very stable, and the APIs have been constantly growing, but rarely obsoleting any knowledge of previously existing APIs.

    2. Re:I abandoned Java for the same reason by goombah99 · · Score: 1

      The apparently you aren't using many of the now depricated libs or have never tried to use java on multiple platforms and get all the different vms working correctly or done any even management or worried about when garbage collection occurs. In short you are not really doing anything that requires java.

      --
      Some drink at the fountain of knowledge. Others just gargle.
  62. Re:Arghh Python by mzipay · · Score: 1

    You're kidding, right? No, seriously - you've GOT to be kidding. No individual with even the most basic knowledge of Python and Lisp could possibly make such an asinine comment.
    You took a cursory look at Lisp and Python. You noticed some similarities (weakly typed, compiled and interpreted, excellent for prototyping, procedural and object-oriented, common key words like "def", "class", and "lambda"). You checked dates, discovering that Lisp has been around for a helluva lot longer than Python. Then, like a class-A flamer, you got the idea that by putting it all together you could manufacture some deep and meaningful "ubergeek" post on /. to intrigue and amaze slashdotters everywhere who would look in awe upon your brilliant post and say, "Hmm... it's the most insightful post I've ever read."
    Your post is not even good enough to be flamebait - it's just laughably misinformed.

  63. Re:An indictment of the Python programming languag by Anonymous Coward · · Score: 0

    Wow, what a rebuttal. In light of these new facts, I'll be reconsidering my use of Perl in favor of Python. Thanks!

  64. Re:An indictment of the Python programming languag by Anonymous Coward · · Score: 0

    A troll? Really, all your objections are just about matters of taste, mostly about minor syntactical issues; so your critique is pretty subjective. Python is only two years old? Where'd you get that idea from. Or did you dredge up some old troll from the past? You come across as very pompous.

  65. Why such confusion over something so simple? by Kingstrum · · Score: 1

    I'm still teaching myself the deeper mysteries of Python, but its always been my favorite language: clean, simple, easy to learn, and very powerful. So, while I understand the reviewer's confusion over the author's methodology, I'm more troubled by the fact that the writers seem to have overlooked one of the nicest features of Python:

    from __future__ import *

    *poof* Instant time machine. Your snazzy 1.5.2 classic scripts can now use facilities they didn't have before. It would seem easier to write a good chapter covering this element, let people know that it's available, then use 2.x.x for all of your examples. Anyone who needs to catch up (or stay behind, relative to your perspective) can do so with very little pain.
    Beats the hell out of starting over from scratch.

    1. Re:Why such confusion over something so simple? by Jerf · · Score: 2

      I'm not certain if this is some sort of obscure joke, but you misunderstand the future statement. It turns on language features that are being phased in on a particular release. It does not and cannot activate those features in a language version that does not support it. 1.5.2 doesn't have the __future__ directives at all.

      Really, do you think these experts would have missed something that obvious?

  66. Re:An indictment of the Python programming languag by Da+VinMan · · Score: 4, Insightful

    Aside from the point about lack of declaration of variables, you're points against Python all reduce down to syntax issues.

    It's a good thing you posted AC. I wouldn't want to take credit for that dreck either.

    Oh, and if Python were only two years old, then I wouldn't have been able to do the Python project I did for a client when I did.

    Have you even used Python? I didn't think so. I guess that if you want to be cynical and condescending about a language just because you're a self-appointed language guru, then please go ahead. But I think we would all prefer that you keep your opinion under wraps until it is informed and rational.

    --
    Please mod this post only if you think others should/n't read this. I have enough ego^H^H^Hkarma. Thanks!
  67. Re:An indictment of the Python programming languag by Hobbes_2100 · · Score: 1
    You know, it's posts like this that ruin my day and make me waste time responding.

    I have seen languages come and I have seen languages go. I have personally written compilers, interpreters, translators, instrumentation preprocessors, etc., for ten or so. Python is probably the weakest addition to computer science in quite some time; it is arguably a giant step backward.

    I won't respond to this. I'll just offer a translation: "I'm a smart expert and I know what I'm talking about. Really. I'm a REAL expert. Listen to me."

    Talk about f'in hogwash.

    It is a very undisciplined programmer indeed who would rather rely upon error-prone white space placement than upon precise delimitation of ranges by actual tokens.

    And it's a fuckin' moron who can't use a decent enough editor to 1. deal with spaces/tabs issue and 2) has so many levels of indentation in their code that it isn't obvious what belongs where.

    to assign semantic significance to white space

    With all your expertise I'd think you'd realize that the whitespace has SYNTACTIC meaning but does not affect the SEMANTICS of the program (after you parse, you don't keep the whitespace ... or any tokens for that matter ... around).

    Python does not support declarations of variables

    Humm, neither does LISP. Nor is it necessary. And your argument about initialization is a joke. In C if I write "int i;", it isn't initialized. And a new programmer might think it is. Which is worse? Declarations are a waste of time. If typing is needed for performance reasons, you should be able to add it later (ala LISP). But to require to get code to run. Humph.

    patched a posteriori

    Humm, "patched inductively"? or perhaps "patched from derivations by reason"? What the fuck, are you just making up meaning as you go? "Patched after the fact" would have worked nicely. Go back to your computer cupboard and leave the Latin to the adults.

    The author of Python has the nerve to trumpet the amazing flexibility of its data structures. I hate to burst his bubble, but he doesn't offer anything that LISP didn't offer forty years ago.

    Yeah, well, when it took C and C++ the better part of twenty or thirty years to gets list structures into the language (via STL), I personally consider it a step FORWARD when a language includes it (lists and other high level data structures) from the beginning.

    Python is only two years old.

    You don't know ANYTHING, do you? If you think Python is two years old, I'll let the statement stand and let that claim RUIN your credibility. (Hint: Python is NOT two years old.)

    BTW, I'm no one and I know nothing. I'm just making random comments.

    Regards,
    Mark

  68. Re:An indictment of the Python programming languag by shredwheat · · Score: 1

    Thanks for that opinion. I will list some of the reasons i prefer python to any other language i've used. Oh, i see you've already listed them for me, thanks!

    No bracing
    Clean formatting
    Flexible
    Built for "real world" programming

  69. Re:Python icon by rafa · · Score: 2
    --
    [Science] is one of the very few things that raises human life a little above farce and gives it the grace of tragedy.
  70. Re:An indictment of the Python programming languag by Saltheart · · Score: 1
    I guarantee you that this guy is an academician. The problem with these guys is that they have been engrossed in pretty theories and algorithms for so long that they have forgotten what it's like to get work done in the real world. My college courses did very little to prepare for work in the real world. Most of the usefull things that I learned, I had to learn on my own. I'll take a utilitarian, practical language any day over a scientifically correct one. Regarding the latter, I find it interesting that different academicians can waste inordinate amounts of time disputing each others view on what is 'correct'. And that's fine as long as something good comes out of it, but keep your pomposity to yourself, AND TEACH YOUR STUDENTS SOMETHING THAT IS VALUABLE IN THE REAL WORLD.


    In my experience, 75% of the value of a development platform in the real world is determined by how it answers the following question: How fast can I get the work done?

  71. It IS clear how indentation works by cyba · · Score: 1

    > But it isn't made clear how the interpreter decides what is more deeply indented than what.

    The algorithm that Python uses is described here.

    Parser doesn't see spaces/tabs, it receives INDENT and DEDENT tokens from lexer.

  72. Re:An indictment of the Python programming languag by Anonymous Coward · · Score: 0

    you're points against Python

    Your spelling really helps your weak arguments.

  73. Re:An indictment of the Python programming languag by Anonymous Coward · · Score: 0

    Yep, I don't understand the hype about Python either. So many times I find myself annoyed by its syntax.

  74. Re:Swapping Values Without Using a Temporary Varia by Anonymous Coward · · Score: 0

    It's not important. It's not even a good idea.

    Using a temp variable isn't any big deal, and this XOR trick won't be efficient on many computer architectures. And if a and b are somehow aliases for the same variable, this trick fails miserably.

    I doubt anyone would try this in real code; I hope not. Imagine someone else comes in and tries to fix bugs, and then sees little "tricks" like this one. It's tough enough to find bugs in clean, straightforward code!

  75. Re:An indictment of the Python programming languag by tbird20d · · Score: 1
    I usually resist answering a troll like this, but then it hit me that you might be (taking yourself) serious(ly). If so, I think you have some language snobbery to overcome.

    First, you rely too much on denigration of people using the language. To wit:
    • ...too lazy to type braces...still don't know where to find braces on the keyboard...very undisciplined programmer...

    I think your arguments are weakened rather than strengthened with this tone.

    • Python is probably the weakest addition to computer science in quite some time

    Oh, so languages exist to advance computer science? How about being useful?

    On to your arguments...

    Your first two points about white space delimitation should be numbered, since they come from straight from the immortal canon of Python detractors. I won't rehash the debate too much. I was at first put off by this feature also. However, other aspects of the language drew me back, and after acclimating myself to this feature I can now say I REALLY like it. It is a small part of a overall philosophy of developing maintainable software that grows on you (the philosophy, not the software).

    Oh, and #2, and #5 are the numbered responses I have chosen for you today:


    • #2: The requirement to delimit with whitespace avoids scoping errors common in some languages when no delimiters are used for single line blocks.


    • #5: The requirement to delimit with whitespace enforces a matching between scoping and its visual indicators, making maintenance easier.

    It's interesting that you would raise some minor nits about syntax with Python, and then bring up Perl!!! Perl is jokingly referred to as a "write-only" language because of the way it tersely uses complex syntax, side effects and multiplicity of allowed constructs. I don't intend to detract from Perl - it's combination of terseness and expressive power are very useful for a wide range of applications, and appealing to a large number of programmers.

    Having translated large programs from Perl to Python, I can say that in my experience the expressive power of the languages is similar. The difference is that 6 months later I can read my Python code.

    Also, having written and maintained large programs with Python, I can tell you from first hand experience that the other "problems" you mention (lack of variable declarations, tuple singleton syntax) simply aren't a big issue, if an issue at all. I'm trying to remember if I've ever even declared a singleton tuple...

    As for your attack on Guido (the author of Python) you'll have to be more specific. When did he say Python had more flexibility than Lisp? This is a strawman you set up yourself. Python has very flexible data structures, probably borrowing a lot from Lisp and other languages. It's the entire package of simplicity in design (everything's a namespace), enforcement of rules to enhance maintenance, and expressive power that characterize Python.

    I know you'll think this is condescending, but why don't you give the language a serious try before condeming (or indicting) it. Your arguments come off as puritanical nitpicking by someone unfamiliar with the "karma" of the language. I have used it for several years, in both personal and commercial settings, for both large and small programs. And it has worked very well for me.

    Isn't that the ultimate test of the value of a language?
  76. ALWAYS BUY FROM WWW.BOOKPOOL.COM! by Anonymous Coward · · Score: 0

    They rock. You have GOT to try them.

  77. Re:An indictment of the Python programming languag by dpb42 · · Score: 1

    > Amusing, indeed--but this was excusable when it was penned 23 years ago. Python is only two years old.

    Huh? I've been programming in python for 6 years, and I think it was around for at least a few years before that.

    Your comments about using indentation to represent block structure clearly indicate that you have never actually used the language. I shared those opinions before I started working on a project that used Python. In practice, using whitespace to reflect the block structure is simply not a problem.

  78. Re:An indictment of the Python programming languag by Anonymous Coward · · Score: 0

    build for lazy programmers...

  79. Re:An indictment of the Python programming languag by Anonymous Coward · · Score: 0
    Perl astonishes me with its power and convenience every time I use it.

    Larry Larry Larry... You almost fooled me, but you really should try to hide your identity more careful.

  80. Re:An indictment of the Python programming languag by Ian+Bicking · · Score: 2
    Oh! A language debate! I love those, though a more thoughtful and informed critique would have made for a better starting point... and this is just a troll (moreso since it's an AC) but I'm feeling bored.

    Python provides no apparatus--other than indentation--to delimit the scope of a control flow construct (loop, conditional branch, etc.).
    No one who actually spends time writing Python code has any real problem with the indentation. Some like it more than others, but anyone can learn to deal with it. If you don't indent your code properly anyway, then you are the poor programmer.

    The issue of tabs and spaces being mixed is well known and debated in the Python community, and mixing is considered very poor form. There are code checkers to avoid this, and Python can be run to reject mixing as a syntax error (personally, I hope this becomes the default in a later release).

    I was shocked ... there was no means to determine to what class an object belongs based upon its handle.
    I'm not entirely clear what you mean by this, "handle" is not clear term. Perhaps you mean, based on the variable name, you cannot tell the class? (Neither by name, nor by looking back in the code for a declaration on that name)

    This is true. Perhaps you do not understand the style of programming that Python encourages -- it's roots lie in Lisp and Smalltalk, not C or Fortran. I.e., fully dynamic typing, where an object's type is incidental, but it's properties are essential. If you don't understand that kind of programming, lack of typing will seem like a deficiency.

    Almost incredibly, Python does not support declarations of variables: variables merely spring into being when they are first referenced.
    Not true. Variables spring into being when you initialize them. Python is not like PHP or Perl in this regard -- there is no default value for an uninitialized variable.

    Lack of declarations is not a large source of bugs in actual use, and those bugs that do exist are shallow and easy to fix. Deep bugs are dangerous, but this does not often lead to deep bugs (though language that allow uninitialized variables can get themselves into trouble).

    The author of Python has the nerve to trumpet the amazing flexibility of its data structures ... I hate to burst his bubble, but he doesn't offer anything that LISP didn't offer forty years ago.
    It's built-in data structures are useful, and C (and even Java) are simply lame not to include them directly in the language. Lisp is another matter (though, again, the literal data types available are slim). Python tends to have fairly Lisp-like semantics, and that's okay. Designers of Python have never claimed to be revolutionary -- rather, they have tried to take the best features of languages that have come before, and create a language that puts them together in a pleasing way (unlike, say, Perl that takes every feature, throws them into a big heap, and calls it freedom).

    ( ) delimits tuples as well as expressions leads to the need to write ( x , ) ... With a bit more thought, something more professional could have been conceived.
    Such as? [ ] and { } are taken (and by data structures that are used more often than tuples). It works, and you get over the (x,) thing really quickly.

    Obviously from this critique, you have never seriously used the language. You only are able to critique its outermost veneer of syntax, and you don't have the knowledge to make any comment on the power of its semantics. The wise language designer knows semantics are more important than syntax (though syntax can get in the way, Lisp being the primary example).

  81. Re:Swapping Values Without Using a Temporary Varia by self+assembled+struc · · Score: 1, Offtopic

    pyhton isn't special because it can do crap like that. you can do that in basic. or c. or ada. or assembly. whatever.

    b = a + b;
    a = b - a;
    b = b - a;

    there's a few ways to solve this problem, and using white-space agnostic languages to boot.

  82. More of an encyclopedia than a cookbook by t482 · · Score: 1

    my review from amazon:
    This book is more like an encyclopedia than a cookbook - each section is introduced and written in a different style and different sections are stronger and more cohesive than others. Some sections are bursting at the hinges and others feel like they are incomplete (like the algorithms section).

    The introductions to each chapter alone are worth the price of the book. Each introduction is written by a different Pythonic luminari, such as Fredrik Lundh, Tim Peters, Alex Martelli, Guido van Rossum and many others. These literary pieces are insightful, humorous and excellent.

    I love python, it follows Albert Einstein's principle Everything should be as simple as it is, but not simpler . As such, this book plays a valuable addition to my library. However, if you are just starting out I would recommend getting a different book first.

    By the way - Redhat ships with python 2.2 you
    just need to change your #!/usr/bin/python to
    #!/usr/bin/python2

    Anthony

  83. Re:Slashdot topics - scripting - not by Splork · · Score: 2

    Don't make a scripting topic and expect all talk of python and perl to be done there. they are both full programming languages. (as are others such as tcl)

    scripting is something can can easily do with them but should not be portrayed as a limitation.

  84. Re:Swapping Values Without Using a Temporary Varia by Anonymous Coward · · Score: 0

    congratulations, you have just created not one, but two temporary variables -- which are, in fact, first class objects, requiring instantiation. Efficient.

  85. Python Business Forum by Anonymous Coward · · Score: 0

    Companies basing their business on Python should take a look at the PBF http://www.python-in-business.org

  86. Re:Arghh Python by Anonymous Coward · · Score: 0

    UberGeek! Cool - never heard that one.

  87. Has nothing to do with language speed by metalhed77 · · Score: 2

    I'd wager that since that averages out to 12 seconds per query that your metric is useless, besides DB queries reflect the database more than anything else, all the language does is send a string off to a C API which then queries the DB and gets the info. Same thing with the GUI. A better metric for the language would be say processing large amounts of data.

    --
    Photos.
  88. Re:Swapping Values Without Using a Temporary Varia by ChadN · · Score: 2

    You forgot the part where A and B are declared as 'float', and so this clever trick is really stupid and/or invalid, a lot of the time.

    --
    "It's overkill, of course. But you can never have too much overkill." - Anonymous Slashdot Coward
  89. Re:An indictment of the Python programming languag by theNeophile · · Score: 1
    Your spelling really helps your weak arguments

    Yep yep, your attacking his spelling sure shows how weak his argument is. Plus, it's easier then actually finding fault with the content of what he said.

  90. Re:An indictment of the Python programming languag by Da+VinMan · · Score: 2

    Ah yes, another attack from yet another person too cowardly to actually own up to their writing. I don't normally make mistakes like that, but I am big enough to own up to them and correct myself when needed. I can't say the same thing about most ACs.

    For the record (without even using a dictionary):
    their = possessive
    they're = they are
    there = not here

    It's a typo that's all. I made a mistake.

    --
    Please mod this post only if you think others should/n't read this. I have enough ego^H^H^Hkarma. Thanks!
  91. Re:Swapping Values Without Using a Temporary Varia by dvdeug · · Score: 2


    b = a + b;
    a = b - a;
    b = b - a;


    In the case where you're using unsigned integers with wrap around semantics, yes. In the case that a,b are floats, integers on some systems (this won't work on signed magnitude systems, or in programming languages (like Ada) that have overflow checking), it doesn't work. It's nowhere as clear as "a,b = b,a", and doesn't work on general variables.

  92. It isn't about them eating the pythons... by Anonymous+Brave+Guy · · Score: 2

    Trust me, it's not nearly as funny if a snake really did want to eat you when you were younger.

    (Yes, one actually did, during a visit from a zookeeper to my school to show us what reptiles were really like. I was sitting at the end of a line of small children, and it started coiling around me... :-o I can handle spiders, or enclosed spaces, or high altitudes, but to this day, snakes scare the living **** out of me -- unless I'm programming in one, of course.)

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    1. Re:It isn't about them eating the pythons... by Fjord · · Score: 1

      It didn't want to eat you then. Constrictors strike their prey with their mouth to get a good grip on them before they very quickly wrap their prey. Then then patiently wait until their prey breathes out, and on each exhalation, tighten their grip and do not allow it to inhale. Eventually, the prey loses consciousness due to lack of oxygen, and then dies. Often, if the prey is too lare, the python will coil around it and squeeze the body while pushing it out of the coil, inorder to dislocate the bones, making it easier for ingestion.

      You can see the first part of this phenomenon (strike and wrap) in this file, where a 14 foot snake we had in my wife's reptile rescue begins the process of eating a chicken.

      A snake crawling on you and then constricting is usually doing it because they are unsure of their "footing". It's a natural response, and occurs when the tree they are in is blown by a gust of wind. These squeezes can often be fatal, because the human being squeezed will being to panic and this makes the snake hold on tighter. Because of this, it's important to never wrap even a 5 footer around your neck, leaving part of it under the arm. If you are being constricted by a snake, the best thing to do is to have someone there who knows what to do. You have to stay still, while they unwrap the snake from you starting with the tail. Even the 15 footer we have right now isn't strong enough to resist a from-the-tail unwrapping because its muscles just aren't made that way. Unwrapping from the head is almost futile, however, as it is like armwrestling a guy with a 1 foot thick arm, and you have to move his hand 7 feet.

      --
      -no broken link
    2. Re:It isn't about them eating the pythons... by Anonymous+Brave+Guy · · Score: 1

      Hey, thanks for the reassurance. You learn something new every day, I guess. :-)

      (Kinda spoils the whole joke, though... :-/)

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  93. Obligatory Enterprise joke by Anonymous+Brave+Guy · · Score: 2

    T'Pol: It's a Klingon delicacy... But only when it's alive.

    Hoshi: [Winces]

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    1. Re:Obligatory Enterprise joke by BlackBolt · · Score: 1

      Who, me or the rattler?

      Cuz I'd just taste like coffee and hamburgers and pizz-- oh, wait, that's a good thing, isn't it... what I mean is, all I eat is raw sewage and black candlesticks. If you're going to cannibalize someone, please choose the Cowboy Neal option, like everybody else. I mean, he gets Christmas Cards from Pizza Hut, for chrissakes.

      WAIT A MINUTE!!! I just googled T'Pol. I'm definitely your man, forget what I said before. In the Klingon dictionary, beside "delicacy best served alive", it's got my picture. Ohhh, yeahhhh. Me me me me me me me. All me.

      Ahhh, if only life were as good as these Slashdot postings, eh?

      BlackBolt

  94. Oops :-( by Anonymous+Brave+Guy · · Score: 2
    more concise: a^=b^=a^=b;

    And even more wrong, in just about every language I know that supports an xor-assignment operator, because it modifies the same variable multiple times in one statement. :-(

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  95. versioning by ajole · · Score: 1

    FreeBSD? ports? 2.2? 1.5? take your pick.

    --
    -P ...and the boy pulled open his bleary eyes an discovered the python he always knew he was.
  96. Scripting is cool by fm6 · · Score: 2

    You make it sound as if "scripting language" is some kind of negative term. Hey, scripting languages have their strengths and weaknesses. You couldn't run the WWW without them, but I'd never use them to write CPU-intensive programs. And it's interesting to compare them to each other.

    1. Re:Scripting is cool by Anonymous Coward · · Score: 0

      By the way, Python can be used for some cpu-intensive tasks with the use of the Psyco specializing compiler module,
      so there is some good hope that people can have their cake and eat it too.

  97. Worse than I thought by fm6 · · Score: 2
    Oh lord, there's a "developers" topic? Which is not on the topics page? And is different from "programming"?

    Anyway, you seem to be saying that next time we get a story about Ruby or TCL, we should lump them together with all the "other" programming languages, despite their kinship to other scripting languages, such as Perl, Python, and PHP.

  98. I like python... by Anonymous+Brave+Guy · · Score: 2

    ...But I couldn't eat a whole one.

    SCNR. :-)

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  99. Topics? Sections? by fm6 · · Score: 2
    That's because we have a specialized apple section [slashdot.org] of slashdot. What, should every story on that page have the same generic apple icon?
    I guess not. But then somebody needs to explain the different between topics and sections.
  100. Re:Might actually be an interesting book to check by Tonetheman · · Score: 1

    Problem is that it is the OLD (ahem) 1.5 something python. I want to use quark but it has the old python and I have the new python already installed... not sure how well those two will play... if they will play at all.

  101. same problem with /bin/sh on Red Hat by Michael+Wardle · · Score: 1

    The same problem occurs in relation to bash as /bin/sh. Try making something like ash or ksh the system's /bin/sh (cd /bin; ln -f ksh sh) and watch Red Hat's system scripts break. This is bad because /bin/sh should either be the original Bourne shell or Korn shell (which reportedly comes closest to POSIX shell specifications), but Red Hat relies on many Bash extensions.

  102. HTML: Great for exposing flaws by HuguesT · · Score: 1

    To be or not to be; that is the question, Whether 'tis nobler to suffer the slings and arrows of outrageous fortune, or by opposing, end them. . . .

  103. Re:An indictment of the Python programming languag by Kirruth · · Score: 1
    Indeed, Python now has the dubious distinction of being the first language since FORTRAN 66 and SNOBOL to assign semantic significance to white space.

    You mean, apart from the most popular functional programming language, Haskell 98? Which, by the way, is strongly typed but doesn't have variable declarations. And doesn't have any flow control either (obviously). You need to get yourself a new paradigm.

    --
    "Well, put a stake in my heart and drag me into sunlight."
  104. close but no banana by DrSkwid · · Score: 1

    To be, or not to be, that is the question:
    Whether 'tis nobler in the mind to suffer
    The slings and arrows of outrageous fortune;

    --
    There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
  105. Re:HTML Email whining by DrSkwid · · Score: 2

    No; it's also for people who want me to want a half hour to get my mail over my modem, so I can get the exact same message but with lots of HTML tags. (And invariablly lots of HTML tags - it never bears any resemblence to clean hand-written HTML.)

    so you'd prefer me to send you a png attachement,
    or maybe an html document in a gzip?
    It seems like you are troubled by the poor use of HTML email not HTML email par se.

    And what happens when you need to make a change to that form? Why not just stick it your own private webspace?

    It's a little thing called 'convenience'. It aids workflow. I know it's only a little step but imagine getting a letter saying "there's a picture on the noticeboard, go look at it". HTML improves the flow of communication. People are not always great at mentally task switching and when they are "reading their email" firing up a browser breaks that task.

    Ah, yes; the wonderous feeling of "you crossed my mind, but I couldn't be bothered to walk to the store for a _real_ birthday card".

    I'll take that as a "no". Last time I looked I couldn't embed sound and video in a store bought card.

    Again, it's the immediacy that's makes the difference. Imagine opening your card and getting a note "your card is on the table" and looking to the table there is your card on public display.

    Email is a provate thing, the web is a public thing. Even if it's on the LAN the psychology of it makes a difference.

    I fail to see how this could be made richer by adding HTML.

    For in that sleep of death, what dreams may come

    HTML seems to be used as a means to doodle on the email, rather then add any information or emotional empact.

    So what? Should we be disallowed enjoyment because *you* can't see any benefit?

    Why do webs sites use colour, graphics, mark up, tables etc. etc. ?

    because people like them

    Now I do concur that having HTML mail on by default is a crazy idea. 99% of the HTML mail I receive is either better as plain text or better to not get at all.

    but to suggest I should be "the first against the wall" because I want to send an HTML christmas card to my friends is short sighted, rude, offensive and promotes banality.

    --
    There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
  106. Re:HTML Email whining by dvdeug · · Score: 2

    so you'd prefer me to send you a png attachement,

    Yes, if what you want to send is a bitmap graphic.

    or maybe an html document in a gzip?

    Yes, if what you want to send me is an html document.

    It seems like you are troubled by the poor use of HTML email not HTML email par se.

    Yes, but as you say

    99% of the HTML mail I receive is either better as plain text or better to not get at all.

    If it weren't for that 99%, there wouldn't be enough reason to support HTML email in most email clients, especially as it has had so many security holes and privacy leaks.

    there is your card on public display.

    Why would it be? All the webcard services give you cookies in the link to make sure it's not on public display.

    Should we be disallowed enjoyment because *you* can't see any benefit?

    Should we all fall silent when you enter the room, because we may offend you? It brings me absolutely no benefit, and I feel free to bitch about it. Feel free to ignore it, but I don't see why I should shut up, because you like it.

  107. a ternary by bharlan · · Score: 1

    Here's the best substitute for a ternary I have seen so far:

    >>> (falseResult, trueResult)[bool(condition)]

    --
    (Reality reasserts itself sooner or later.)