Slashdot Mirror


Python 2.3 Final Released

An anonymous reader writes "Nineteen months in the making, Python 2.3 has just been released. With a plethora of changes since version 2.2, this release is definately worth the upgrade. Be sure to read the Release Notes and the Highlights file for more information."

72 of 371 comments (clear)

  1. impact... by alienhazard · · Score: 2, Interesting

    I wonder what this means to the people at blender who just updated the python API

    --
    > "I allege that SCO is full of it" -Linus
    1. Re:impact... by sketerpot · · Score: 2, Informative
      Pthon 2.3 was designed with backward compatibility in mind. All your old programs should work with 2.3 if they work with 2.2.2, and you'll get some speed improvement. Of course, if you use 2.3-specific modules like logging (based on log4j) and sets (set operations, using dictionaries internally), those won't be compatible with 2.2.2 unless you copy the files from the standard library, which should work.

      In short: don't worry about it. The python developers already have.

  2. Countdown to Gentoo zealotry. by Anonymous Coward · · Score: 4, Funny

    In 3... 2... 1...

  3. Python 3 by Alan+Holman · · Score: 5, Funny

    Wow, finally Python 3! Are they as good as the original Monty Python? I didn't see the second Monty Python...Err... Is John Cleese still in Python?

  4. Whitespace trolling... by Omicron32 · · Score: 5, Funny

    I'm just waiting
    for the trolls to start
    complaing about
    whitespace usage in
    Python.

    That, and what does this mean for improvments to my favourite distro's package management? (Gentoo!)

    1. Re:Whitespace trolling... by Dausha · · Score: 2, Funny

      Don't you mean?

      def waiting (trolls) :
      for troll in trolls :
      complain(troll, whitespace_usage)
      --
      What those who want activist courts fear is rule by the people.
    2. Re:Whitespace trolling... by XNormal · · Score: 2, Funny


      Python:
      Programming the way
      Guido
      indented it.

      --
      Stop worrying about the risks of nuclear power and start worrying about the risks of not using nuclear power.
    3. Re:Whitespace trolling... by BigJimSlade · · Score: 4, Interesting
      What's wrong with { and }?

      What's wrong with it is that it's the syntax for dictionaries. Similar to hashes in Perl, it is a built-in type for Python. Anything wrapped in {} would probably be viewed as an attempt to make a dictionary by the parser.

      I've discussed this with all my software engineering colleagues, and most of them have white space as their only hang up about the language. I thought this was pretty petty at first, given the other strengths of the language, but one person brought up an extremely good point. A co-worker at his company is blind. He said that having to deal with white space while coding was near impossible (maybe he uses a "pretty printer" or code beautifier after the fact? I don't know) Has anybody on /. had experience with a blind user of Python? How did they work around this issue (if at all?)

      I do think it would be nice if there was a way to open and close a block (someone later down in the comments suggested preprocessor comments of
      #begin
      and
      #end
      ) such that one could use either method. Perhaps there would even be a built in function of the interpreter to spit out the code one way or the other.

      I must say I've gotten used to the whitespace over the past year. Using a decent editor makes life much easier in this respect. I would encourage anyone who hasn't tried out Python for this reason alone to give it a shot for a few weeks and see what you think.
    4. Re:Whitespace trolling... by ProfKyne · · Score: 3, Insightful

      In general I find Ruby's way easier to read than Python's, especially in the case of weenies who haven't yet learnt to indent properly and have tabs/spaces randomly mixed in with their indents (a practice that seems so common as to outnumber the more traditional spaces OR tabs methods many times over).

      Interesting... seeing as how Python doesn't let weenies indent improperly, and you can run Python scripts with a flag (-O) that gives warnings if tabs and spaces are intermixed in the whitespace... you would think that Python's way would be easier.

      --
      "First you gotta do the truffle shuffle."
  5. Reviewing a book 101 by Anonymous Coward · · Score: 2, Interesting

    What did it help you do? Work on your reading skills? Start your camp fire? Reach the top shelf?

    How did it help you? Did you really need help? If so was this book uniquely helpful or do you think others would have helped too?

    Are there other reasons why it was great? Was the author witty and entertaining? Or was he dry and to the point? Was his writing unusually clear and illuminating? Did he "speak to you"?

    I'm not saying every comment here has to be a full book review, just that yours was devoid of any helpful content.

    1. Re:Reviewing a book 101 by Sir+Haxalot · · Score: 5, Informative

      Ask any Python aficionado and you'll hear that Python programmers have it all: an elegant language that offers object-oriented programming support, a readable, maintainable syntax, integration with C components, and an enormous collection of precoded standard library and extension modules. Moreover, Python is easy to learn but powerful enough to take on the most ambitious programming challenges. But what Python programmers have lacked is one concise and clear reference resource, with the appropriate measure of guidance in how best to use Python's great power. Now Python in a Nutshell fills this need.

      In the tradition of O'Reilly's "In a Nutshell" series, this book offers Python programmers one place to look when they need help remembering or deciphering the syntax of this open source language and its many modules. This comprehensive reference guide makes it easy to look up all the most frequently needed information--not just about the Python language itself, but also the most frequently used parts of the standard library and the most important third-party extensions.

      Python in a Nutshell focuses on Python 2.2 (and all its point releases), currently the most stable and widespread Python release. This book includes:

      A fast-paced tutorial on the syntax of the Python language itself

      An explanation of object-oriented programming in Python, covering both the classic and new-style object models

      Coverage of other core topics, including exceptions, modules, strings, and regular expressions

      A quick reference for Python's built-in types and functions, as well as the key modules in the Python standard library, including sys, os, time, thread, math, and socket, among many others

      Reference material on important third-party extensions, such as Numeric and Tkinter

      Information about extending Python and embedding it into other applications

      Python in a Nutshell provides a solid, no-nonsense quick reference to information that programmers rely on the most. This latest addition to the best-selling "In a Nutshell" series will immediately earn its place in any Python programmer's library.

      Synopsis
      In the tradition of O'Reilly's "In a Nutshell" series, this book offers Python programmers help remembering or deciphering the syntax of this open source language and its many modules. This comprehensive reference guide should make it easy to look up all the most frequently needed information - not just about the Python language itself, but also the most frequently used parts of the standard library and the most important third-party extensions. The book includes: a fast-paced tutorial on the syntax of the Python language itself; an explanation of object-oriented programming in Python, covering both the classic and new-style object models; coverage of other core topics, including exceptions, modules, strings, and regular expressions; a quick reference for Python's built-in types and functions, as well as the key modules in the Python standard library, including sys, os, time, thread, math, and socket, among many others; reference material on important third-party extensions, such as Numeric and Tkinter; and information about extending Python and embedding it into other applications.

      Happy? :)

      --
      I have over 70 freaks, do you?
  6. question to practical programmers by Maimun · · Score: 4, Interesting

    At the top of the list of new features they have sets. The first paragraph says that sets are implemented by hashtables. I wonder whether it is really meaningless from the "practical" point of view to implement sets with data structures like red-black trees or Fibonacci heaps. The advantage of the latter over hashtables is a solid bound on the worst case running times.

    1. Re:question to practical programmers by SilentStrike · · Score: 2, Informative

      Essentially, hash tables are preferred over balanced trees because they are usually faster in practice.

      Python developer showing preference to hash tables over balanced tres.

      I would also like to see balanced trees in the library, if for nothing more than sometimes ordered iteration is more useful than fast lookup, but oh well. I believe having hash tables but not balanced trees is much less bad than the other way around (like standard C++), in which there are balanced trees but no hash tables.

    2. Re:question to practical programmers by elflord · · Score: 2, Insightful
      The advantage of the latter over hashtables is a solid bound on the worst case running times.

      Another key advantage, is that RB trees are automatically sorted.

      I'd suppose they use hashtables because they're interested in good average case performance, especially for large tables. I doubt they'd care about worst-case performance -- I suspect that most time-critical code is not written in python.

    3. Re:question to practical programmers by jcr · · Score: 4, Insightful

      I suspect that most time-critical code is not written in python.

      Depends on which time is critical: CPU time, or programmer time?

      -jcr

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
    4. Re:question to practical programmers by elflord · · Score: 4, Insightful
      I wasn't trying to dis python, but the point is that most python programmers (even the ones who are interested in performance) are probably thinking "I want this to be as fast as possible on average", not "someone (possibly the programmer) will die if this code does not run in 0.05ms. In one case, you're interested in average case performance, in the other you're interested in worst-case.

      For most web applications, you only care about average case, but for embedded systems, medical equipment, air traffic control systems, etc, worst case may also be very important.

    5. Re:question to practical programmers by miu · · Score: 2, Insightful
      Another key advantage, is that RB trees are automatically sorted.

      Most stl map implementations are based on a RB tree, and often cause memory fragmentation. That's not the end of world for most programs, but data being located on many different pages can trash average access times for threaded programs (although constant use of the memory allocator probably harms the program itself more).

      A hash gives good memory locality and good average lookup performance, if data is constant (or near constant) a sorted vector gives you excellent lookup performance and very good memory locality.

      But I don't think flat out optimization is that important to python, otherwise they'd use low level hacks like perl reading directly out of the stdio FILE buffers to optimize IO.

      --

      [Set Cain on fire and steal his lute.]
    6. Re:question to practical programmers by scj · · Score: 2, Insightful

      I believe the reason is that sets in Python are implemented in the Python language itself. Since Python already has hash tables implemented in C, it was easy to write a good set class by using a hashtable. To get the same level of performance with another data structure would mean writing and maintaining a bunch of C code.

      The Python developers could always rewrite the set class in C using Fibonacci heaps at some later time. By writing it in Python, they get a reasonably good implementation now where people can use and experiment with it and suggest improvements to them before commiting to a harder to maintain C version.

    7. Re:question to practical programmers by Ed+Avis · · Score: 3, Interesting

      After the recently-implemented algorithmic complexity attack against many hash table implementations (story on Slashdot a couple of months ago), many more programmers have reason to be concerned about the worst case. If you are hashing inputs taken directly (or perhaps even indirectly) from the user, then by choosing the right strings an attacker can DoS your system by making lots of hash collisions, so each lookup becomes effectively a linear search.

      I don't know what Python (or other scripting languages) are doing to address this; many on the Python newsgroup seemed not to care and said that the operating system should deal with any process which is using too much CPU time, but I don't know if this attitude is shared by the real Python developers.

      Perhaps for security-conscious applications you could choose to use red-black trees or some other implementation of associative arrays, at least in cases where strings sent by the user are used as part of a hash key. Perhaps Perl's tainting mechanism could help with this.

      --
      -- Ed Avis ed@membled.com
    8. Re:question to practical programmers by Matts · · Score: 2, Informative

      Perl has fixed this in the soon-to-be-released perl 5.8.1

      --

      Matt. Want XML + Apache + Stylesheets? Get AxKit.
    9. Re:question to practical programmers by scrytch · · Score: 2, Informative

      If you want to see an interesting container implementation (based on a trie, behaves like a hashtable) check out Judy Arrays. Judy is bogglingly complex, but it boils down to optimizing for the CPU cache.
      Judy looks fairly promising for some applications I'm looking at. The benchmarks I ran are sort of bogus though since I'm not causing fragmentation by doing other things between inserts and deletes. I suppose the moral of the story is, preallocate if you know your structure is going to get big.

      --
      I've finally had it: until slashdot gets article moderation, I am not coming back.
  7. Platform Competition? by Chromodromic · · Score: 5, Insightful

    Check out Artima if you want to see Bruce Eckel's take on the Python language which, incidentally, with the addition of things like a logging API, and with long-existing additions like Jython, is beginning to look more and more like a viable competitor to Java.

    Why?

    Python carries a LOT of the same advantages, but with a dramatically accelerated prototyping and general development speed, and a few tricks of its own. Plus, via Boost, it interoperates with C++, too. I'm an avid Perl hack, but I have to admit that Python, which even has a whole API for basic game programming is looking more and more attractive for quite a number of things.

    Download soon and often.

    --
    Chr0m0Dr0m!C
    1. Re:Platform Competition? by mixmasta · · Score: 3, Informative

      Maybe you are right but I have written several apps in python and java, and the ones in py left java in the dust. Much less memory for the runtime too.

      --
      #6495ED - cornflower blue
    2. Re:Platform Competition? by wdr1 · · Score: 5, Funny

      ava achieves close to C/C++ performance on low-level code (for loops, arrays, etc.); Python doesn't even get close.

      Wait, now Java people are saying other languages are too slow?? ;-)

      -Bill

      --
      SlashSig Karma: Excellent (mostly affected by moderatio
    3. Re:Platform Competition? by Malcontent · · Score: 3, Insightful

      It seems to me that everything Bruce praises about python also applies to most other dynamic typed scripting languages. Certainly ruby and even php or dare I say it perl.

      He seems more in love with the idea of typeless, brief, dynamic and expressive languages in general. it's just that he learned python first and has gotten good at it. If he picked up Ruby first he would be saying the same things about it.

      --

      War is necrophilia.

    4. Re:Platform Competition? by GooberToo · · Score: 4, Interesting

      This is a common saying when you talk with Python/Java programers. Plus, with something like wxPython, you can have a slick client application to boot.

      Last time I saw unbiased performance comparisions, the difference between Python and Java wasn't really worth talking about.

    5. Re:Platform Competition? by 73939133 · · Score: 2, Insightful

      Maybe you are right but I have written several apps in python and java, and the ones in py left java in the dust. Much less memory for the runtime too.

      There is no contradiction: the Java libraries and the Java runtime have numerous design flaws that cause people to build bloated and sluggish applications in Java. In fact, the same can be said for many C++ frameworks.

      But if you just look at the languages and their implementations, it's easy to compile Java into tight, efficient machine code, while the same is just not possible for Python. Python is a great language with many applications, but it simply is no substitute for statically typed languages like Java, C#, or C++.

    6. Re:Platform Competition? by archeopterix · · Score: 3, Insightful
      I'm really starting to think that the whole static type checking as a requirement for large systems thing is just dogma.
      In fact, Java is a proof of that. Static type checking with most collections being Object holders? If you want typechecking, use a language with some decent type constructors (C++ templates will do, but ML-derivatives have much cleaner type systems). If you implement generics with Object, you defer typechecking till runtime, when your Objects get downcast to whatever you hope they really are.
    7. Re:Platform Competition? by GooberToo · · Score: 2, Informative

      Was nice of you to post as AC. Seems your reading skills need some work. Which makes it obvious why you posted as AC. I said, "it's not worth talking about". I never said Java wasn't faster. That's actually a fairly old version of Python and Java in that comparision. Now then, throw in a benchmark which actually allows for Java's GC to kick in, then you'll see Java's performace stumble, fall and simply cry. In turn, it significantly closes the performance gap. That's the biggest problem with by-n-far, most Java benchmarks. That is, they are short enough to prevent GC'ing from occuring. As such, it looks good on paper but performs much worse in real world applications. Python, on the other hand, constantly pays its collection dues when something falls out of scope. As such, most Java versus Python comparisions heavily bias toward Java. Create a benchmark which runs long enough for Java's collector to kick in, and you'll see a world of difference. Oddly enough, many real world applications help show this difference without problem.

      The fact that python constantly collects is one of the reasons why python has a much smaller memory footprint than java. Don't forget that Python just got 10%-30% faster too. That too should significantly help close the remaining performance gap. Still even more funny, Python has not been significantly optimized to date. That means you can continue to expect python's performance to increase. Java, on the other hand, is pretty much about as fast as it's going to get.

      You need to learn how to compare apples to apples and even know what you are talking about. All of the above is why, in real world terms, the performance differences between Java and Python s not worth talking about. Want to compare performance of wxPython with Swing? Be prepared to laugh until you pee.

  8. Re:Second fucking post by Sir+Haxalot · · Score: 2, Informative

    If you dislike the posts he makes, it might be a good idea to set him as a Foe, and browse at Foe -5. That way you will never have to look at his huge limp phallus again!

    --
    I have over 70 freaks, do you?
  9. Its 20-30% faster !! by vivek7006 · · Score: 4, Insightful

    According to a couple of simple benchmark, Python 2.3 is about 20-30% faster than Python 2.2.3. Some of this speed-up was obtained by removing the SET_LINENO opcodes, which means that the difference is less impressive when comparing "python -O"; the rest was various careful tune-ups.

    This is a big improvement. The biggest advantage of using a programming langage like python is the fast development time (5X-10X faster than C++). If the speed of execution of python scripts can be made comparable to compiled C/C++ code, then it would be awesome. Python programs can never be as fast as compiled code, but if the difference in the speed is not significant, it will be a big win for Python

    1. Re:Its 20-30% faster !! by elflord · · Score: 5, Informative
      If the speed of execution of python scripts can be made comparable to compiled C/C++ code, then it would be awesome.

      Out by an order of magnitude, and not getting closer any time soon. Last I checked, it's out by a factor of 100 or so for small operations (loops, etc) But this isn't a problem in practice -- one can code the speed-critical stuff (whether that be objects, or functions) in C or C++, then wrap them in python, and enjoy all the benefits of python.

      Also, it often happens that 1% of the speed of C and C++ is actually good enough. Sounds slow, but only compared to C and C++ which may be well over 100x faster than what's required.

      Python programs can never be as fast as compiled code, but if the difference in the speed is not significant, it will be a big win for Python

      It is much slower, and unavoidably so. It's a very dynamic language, and this has consequences as far as performance is concerned.

    2. Re:Its 20-30% faster !! by ansible · · Score: 5, Interesting

      Out by an order of magnitude, and not getting closer any time soon. Last I checked, it's out by a factor of 100 or so for small operations (loops, etc)

      Well, regular Python code can see some dramatic speedups, with just a little bit of extra work. Check out Psyco if you firmly believe that interpreted languages will never ever be as fast as C.

      With sufficient cleverness, it may be possible to boost Python beyond the speed of the most highly optimized pre-compiled program.

      Psyco and approaches like it do have drawbacks, but there is some very interesting work going on now with high-level languages.

    3. Re:Its 20-30% faster !! by jgardn · · Score: 3, Informative

      Python is running on a virtual machine that uses a stack. This is what pretty much every high level modern language does, including Perl and Java.

      However, with the addition of Parrot, Python, as well as Perl, will be running on a virtual machine that uses registers rather than a stack. Register based machines are much faster than stack based machines.

      Damian Conway, in a presentation at the Seattle Perl User's Group, demonstrated that you can actually get code that is written in perl that runs only a small factor (like 4 or 5 times) slower than C, rather than many orders of magnitudes (like 100 or 10,000 times) slower. This speedup will benefit Python as well, when it is ported to Parrot.

      In short, Python and Perl, and every other language that is ported to Parrot, will kick some serious butt, and put a lot of C programmers out of work.

      --
      The radical sect of Islam would either see you dead or "reverted" to Islam.
    4. Re:Its 20-30% faster !! by elflord · · Score: 4, Interesting
      If it were possible to compile Python (or any other interpreted language), would this make it anywhere near the speed of C/C++?

      Compiling alone wouldn't bridge the gap. Python already reduces interpreter overhead by using a pre-compiled byte-code. A large part of the problem is in dynamic typing: for example, when you say
      a+b
      in python, it's not equivalent to doing the same in C++. In python, you need to do a runtime type check and then decide what operation to perform, and only then can you add a and b. In C++, the dispatch can be performed compile-time.

      What you really need to get a big speedup is some sort of mechanism that can eliminate a lot of this type checking (the other guy posted a link to an interesting approach to this problem)

      But I've often been impressed with the ease of coding in such a language

      It's a bit of a two-edged sort for the same reason -- the lack of type checking makes it easy to write code quickly, but it also makes it easy to code incorrectly.

    5. Re:Its 20-30% faster !! by GnuVince · · Score: 2, Informative
      Quote from elflord:
      It is much slower, and unavoidably so. It's a very dynamic language, and this has consequences as far as performance is concerned.

      Common Lisp is a very dynamic language, but compilers like CMUCL and SBCL produce programs whose performances match those of C and C++. See http://www.bagley.org/~doug/shootout/ and see how well CMUCL performs.

  10. Re:Why Python is good at our university by The+Bungi · · Score: 4, Informative

    He's a troll. "Fu-Ling Yu" Get it? Haha and all that. He just pastes some links from the quoted article and get modded +5 with alacrity because of his charming "engrish". The stupid mods always fall for it.

  11. Better than Learning Python. by Big+Sean+O · · Score: 5, Informative
    Learning Python is getting quite dated (it covers Python 1.5). I recommend Python: A Visual Quickstart Guide by Chris Fehily. It's a better book than Learning Python, at least.

    I've been learning Python Language for a while, but since I don't work with other programmers, it's taken me quite a while. I learned python the usual way (a mix between the on-line tutorial and Learning Python) and my fluency is improving.

    I picked up this book recently while I was at a convention in Baltimore. I liked its organization: the book features a whole chapter on each datatype (strings, numbers, tuples, lists, and dictionaries). There are also chapters on Control Flow Statements, Functions, Modules, Files, Classes, and Exceptions.

    Because of its organization, it's as useful as a reference as it is a tutorial. Each chapter contains progressively advanced examples that end up demonstrating the finer points of each topic.

    For example, one hint was to use the vars() function creates a dictionary of the local namespace. This makes it useful when string formatting:
    >>> quality = 'color'
    >>> thing = 'orange'
    >>> print "What %s is an %s?" % (quality, thing) # useful for simple formatting.
    What color is an orange?
    >>> print "What %(quality)s is an %(thing)s?" % vars() # more legible and useful.
    What color is an orange?
    The book does not cover advanced topics like Tkinter, Jython, or extending Python with C. Nor does it cover the Library modules (the Python online documentation is actually quite good).

    "Python" is newer, cheaper (22 USD vs. 30 USD), and longer (410pp vs. 368pp) than "Learning Python"

    I would recommend this book to anyone who would like to learn Python. If you're an intermediate Pythoneer, I agree with the parent: you will want to get "Python In A Nutshell".
    --
    My father is a blogger.
  12. Re:I see whitespace is still syntactically relevan by wass · · Score: 4, Insightful
    There's a feature I'd like to see removed.

    I hear this repeated fairly often, but I can not think of any really good reason why whitespace is bad. IMHO, any decent programmer worth his/her salt will whitespace their code anyway for sanity.

    Just to be my own devil's advocate, here are some reasons I can think of off the top of my head. But I don't think any is sufficiently great for not using python strictly because of it's required whitespace syntax.

    Actually, I want to become proficient in python, I've even got a few books, and just haven't gotten around to programming any application in it yet :-( But these are things I've wondered about (regarding the whitespace). Hopefully a seasoned veteran can point out why these aren't substantial problems.

    • Putting a large block of code into a while or for loop.

      In C, if I am quickly hacking some stuff together and realize I want to put 100+ lines into a for loop, I can put brackets around the code and possibly indent it later if I wind up keeping the code for long-term.

      In python I'd have to manually go to all those lines and put the indent in. (I assume EMACS and other editors can do this automatically, if one knows the key combinations).

    • TABS and order of whitespace

      This confuses me. Does python keep track of instances of \t in an input file? Are they distinguishable from spaces? If at some nested level of indentation I'm at [tab][space][space], is a line of indentation of [space][space][tab] at the same nesting level?

      If I'm at [space][space][space][space] can the next level of nesting be [tab]?

    • For decently-complex programs there might be so many nesting levels that the indented code is spaced so far inwards that one needs ridiculously-wide displays for sanity.

      Personally, I don't think I've ever put more than 10 levels of nested blocks in a program somewhere, but I suppose it could possibly happen and might be a problem, especially of someone is restricted to 80-column screen for some reason.

    Other than those rare or obscure issues, I can't think of any reason that mandatory whitespacing should hold someone back from python.
    --

    make world, not war

  13. Re:I see whitespace is still syntactically relevan by Anonymous Coward · · Score: 5, Funny
    There'safeatureI'dliketoseeremoved.Iguessit'sGui do'swayofjustbeingdifferent.


    Isn't that better?

    No cookie for you.
  14. Re:Why Python is good at our university by bsharitt · · Score: 3, Interesting

    It could be worse, people could be learning Basic instead of Pascal and Java. At least they are slightly similar to C. I start programming with Basic and it's haunted me ever since.

  15. Re:I see whitespace is still syntactically relevan by jericho4.0 · · Score: 4, Insightful
    For your first two points, a decent IDE helps a lot, or just being familiar with your editor of choice. It's much easier to figure out the key combo in emacs/vi than it is to indent 50+ lines.

    For your second point, 10 levels of nesting is, IMHO, at least 7 too many. That's what subroutines are for. If you find yourself adding another level after three, it's probably time to look at your design.

    --
    "A language that doesn't affect the way you think about programming, is not worth knowing" - Alan Perlis
  16. Re:I see whitespace is still syntactically relevan by Ian+Bicking · · Score: 4, Informative
    Putting a large block of code into a while or for loop.
    Editor support is very useful in this case. In Emacs you can indent/dedent a region with C-C > and C-C < (i.e., control-C, then > or <); you mark a region by going to one end, hitting C-space, then putting your cursor at the other end (or dragging with the mouse).
    TABS and order of whitespace
    Python treats all tabs like 8 spaces, no matter the location. But mixing tabs and spaces is considered bad and potentially dangerous if you display tabs as something other than 8 spaces. You can use the -t flag to Python to warn you about this.

    Discussions on tabs and spaces can lead to flamewars in Python circles. Many people hate tabs, and a significant majority of code does not use tabs.

    As far as screen width, that's no different in Python than any other language. Deep nesting is a sign of a program in need of refactoring.

  17. Re:I see whitespace is still syntactically relevan by Big+Sean+O · · Score: 2, Interesting

    Most of your problems would be fixed with a good python-aware editor.

    Putting a large block of code into a while or for loop.

    Well, if you had a large block of code to insert, why not make it a function and call it. Also, when you're working with Python, you quickly learn (or assign) the "entab" and "detab" commands, so inserting the tabs aren't a problem.

    TABS and order of whitespace

    Most people have their editors convert tabs to spaces

    For decently-complex programs there might be so many nesting levels that the indented code is spaced so far inwards that one needs ridiculously-wide displays for sanity.

    Someone who is using 10 levels of nested blocks isn't effectively refactoring. Extract method now and then... :-)

    --
    My father is a blogger.
  18. Nice Amazon scam buddy by Voivod · · Score: 2, Interesting

    The only point of your post was to get your nice referral bonus for all the Slashdotters clicking through to Amazon.

    Moderators should know to look out for this... it's way worse than karma whoring. Did you even read this book? I wouldn't be wondering this if your post wasn't so clearly a cash grab.

    If so, it might help if you wrote something useful about why you're recommending it! (And I don't mean cut-n-paste from an Amazon review either...)

  19. Shameless plug by Lulu+of+the+Lotus-Ea · · Score: 4, Informative

    Alex Martelli has indeed written an excellent book. Actually, he almost wrote two excellent ones, since he is co-editor of _Python Cookbook_ too (but the latter is really more of a collaboration of dozens of people in the Python community than a book by an individual).

    However, my book, _Text Processing in Python_, has at least one think over Alex's that is germane to this thread: I make a good effort to cover Python 2.3. I am quite confident that mine is the only book you can actually buy today that does so (I'm sure there will be more titles, and various updates, over time, of course). Don't let my title fool you, btw, I do a bit more than the title entirely admits to. But the title isn't a lie either, it really is focussed on the broad area called "text processing".

    Anyway, there's nothing subtle in my plug. I really will get a couple dollars every time someone buys one (unlike the somewhat odd insinuation downthread about Sir Haxalot doing so). But then, I also invite everyone to read the entire text for free at:

    http://gnosis.cx/TPiP/

    So you can have something for nothing too, if you want.

    David Mertz

  20. Re:I see whitespace is still syntactically relevan by Cranx · · Score: 4, Insightful

    The reason I never bothered with Python is because of the whitespace issue, and I'll tell you why:

    I don't trust that blocks are properly grouped.

    When I program in C++, Java or even Ruby, and I create a new block, the first thing I do is close the block. Any code I put in the block I indent, but if the block grows, or my indenting gets goofy, I don't have to fear that my block is now improperly closing.

    If I paste in a few quick lines of code for debug purposes, and it just happened to be indented differently than where I was pasting it, that would screw up the block closure unless I went and tabbed everything correctly. Sometimes, I *like* that the temporary code is indented wrong because it helps remind me to comment it out or remove it when I'm done debugging.

    The whitespace thing is just too weird. It generates a lot of feelings that I might screw up my blocks. That sort of anxiety shouldn't be there; I shouldn't be so worried about blocks closing.

  21. Re:ATTENTION! by larry+bagina · · Score: 5, Informative
    Upgrading to Python 2.3 will _not_ increase your skill levels, and will NOT make your AOL downloads faster!

    Actually, it could. The PHP crowd blew every horn they could find when yahoo switched over to PHP, but AOL has been using python behind the scenes for a long time with little fanfare (or problems). So if it's AOL doing the upgrading, it might help your AOL downloads be faster.

    --
    Do you even lift?

    These aren't the 'roids you're looking for.

  22. Re:Boolean support by jdfox · · Score: 3, Insightful

    For simple flags, yes, "1" is quicker to type than "True". But Booleans can make other kinds of code clearer:

    "For example, if you're reading a function and encounter the statement return 1, you might wonder whether the 1 represents a Boolean truth value, an index, or a coefficient that multiplies some other quantity. If the statement is return True, however, the meaning of the return value is quite clear."

  23. Re:definately? by joe_bruin · · Score: 4, Funny

    your new hear, i take it.
    we definately do not waist are time with speling and grammer, you looser.

    in the immortal words of homer*:
    "if i spelled cat 'C', 'A', 'T', you'd know what i mean"

    * simpson, homer j. not that other guy.

  24. Re:how about lists by Anonymous Coward · · Score: 2, Insightful
    • It would be nice if python had lists with a head and tail
      Python lists are a contiguous array. It's O(1) to get to the head or tail or anything in between. You might be thinking of lists from another language, like Lisp. Or you might be looking for a doubly-linked list implementation, which is easy to implement but rarely needed in real code.
    • a collector instead of reference counting
      It has reference counting with a collector for cycles. What's wrong with that? BTW, it's an implementation choice. Jython uses Java's native gc. Python uses ref counting because that works better with C extensions
    • maybe a decent attribute analysis so that the expression "a"[1] is barfed on before being run.
      Well, I've been known to insert "1/0" as a debugging aid. It's an easy way to raise an exception. Python deliberately aims for late binding and a clean, understandable implementation. What you want breaks both, especially since '''if 0: "a"[1]''' must not be barfed on.
  25. Re:Why Python is good at our university by talleyrand · · Score: 3, Funny
    I start programming with Basic and it's haunted me ever since.

    Haunted? Leave it to dearly departed Edsger Dijkstra to say how it really is:

    ``It is practically imposible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.''

    --

    "My fingers Emit sparks of fire in Expectation of my future labours." William Blake
  26. Re: Why Python is good at our university by gidds · · Score: 2, Insightful

    Personally (and knowing both languages well), I'd consider that a problem with C, not with Java...

    --

    Ceterum censeo subscriptionem esse delendam.

  27. Really, Dr. FoolingYou by thelexx · · Score: 3, Informative

    This guy is a TROLL people. All the others calling his bluff got modded into oblivion. Read some of them, and/or take a quick look at this dudes posting history. I've given up the -1 mod I had used to point this out instead, karma be damned. Anyone who makes a hobby of publicly mocking other racial groups while hiding behind an internet connection deserves to be called out.

    --
    "Gold still represents the ultimate form of payment in the world." - Alan Greenspan, 1999
  28. Re:I see whitespace is still syntactically relevan by smoondog · · Score: 2, Informative

    I love python, I use it alot. That said, I hate the whitespace problems with the language. I cannot figure out why they don't at least *give* you the option of not using that horrible, horrible design. Why is it flawed? In my opinion it is flawed because a miss tabbed document cannot be reliably retabbed without knowledge of the code. For example:

    while 1:
    ---->while 1:
    --------->dosomething;
    xxxxx>i+=1;

    Now where did the i+=1 go? I don't know. The way I deal with it is by doing this:

    while 1:
    ---->while 1:
    ---------->dosomething;
    ---------->pass;
    --- ->somethingelse;
    ---->i=i+1;
    ---->pass;

    But that's a poor solution, because it isn't a standard. Add f*ing c-like bracket block notation already! It isn't that hard and if you don't want to use it then don't. I don't get it they add all of these wierd obfuscated lets-see-how-long-we-can-make-a-single-line-of-cod e additions but not this. Dumb, IMO. /rant

    -Sean

  29. Re:From relevancy to troll and back. Whitespace by brian_olsen · · Score: 2, Informative

    I really don't understand the problem here, and why people must cavil over a non-issue like required whitespace. If you don't like it, don't use it. End of story.

  30. Nobody Expects the Whitespace Inquisition by jefu · · Score: 2, Informative
    Our chief weapon is trolling

    Our two chief weapons are trolling and casting nasturtiums

    Our three chief weapons are trolling and casting nasturtiums and not paying attention to what we're saying....

    So your favorite language is whitespace neutral - completely so, right?

    No preprocessor lines (C, C++) that terminate on an end of line (which I consider whitespace).

    No comments that terminate on the end of line? (Java, C#, C++, Perl, and so on )

    How about end of line embedded in strings? Is that legal (in which case is the newline part of the string or not)?

    Extra credit to anyone who can name a language that treats whitespace either as completely neutral in all situation (including tabs and end of line markers), or as meaningful in all cases. (And for slashdot regulars I'll rule out WHITESPACE up front).

    And, of course, there is a solution. Just use
    #begin
    at the beginning of a block and
    #end at the end of the block. Of course, like any sensible programmer you'll indent the block as you do.

    And while you are at it, if you like semicolons, you can always add #; to the end of statements.

    1. Re:Nobody Expects the Whitespace Inquisition by ProfKyne · · Score: 2, Informative

      And while you are at it, if you like semicolons, you can always add #; to the end of statements.

      Actually, Python allows the user of semi-colons at the end of statements in most cases. Think of it more as if Python doesn't enforce them.

      --
      "First you gotta do the truffle shuffle."
  31. Re:I see whitespace is still syntactically relevan by Tyler+Eaves · · Score: 2, Interesting

    easy solution.

    while something someval: #{
    do.something()
    while x 10: #{
    print x
    #}
    #}

    --
    TODO: Something witty here...
  32. Re:how about lists by axxackall · · Score: 2, Informative
    head=list[0]
    tail=list[1:]
    Does it help?
    --

    Less is more !
  33. Re:I see whitespace is still syntactically relevan by Courageous · · Score: 2

    If I paste in a few quick lines of code for debug purposes, and it just happened to be indented differently than where I was pasting it, that would screw up the block closure unless...

    Actually, the chances are it would generate a Syntax Error.

    C//

  34. it's a feature by mkcmkc · · Score: 2, Insightful
    I'd consider the (slightly) increased difficulty in autogeneration to be a feature rather than a problem. 99% of the time, autogenerating code is a really lame idea. The other 1% of the time, you ought to be generating the indentation, too, for readability/debugability. So Python doesn't really lose here.

    --Mike

    --
    "Not an actor, but he plays one on TV."
  35. Re:Why Python is good at our university by Ianworld · · Score: 2, Interesting
    At my school the basic programming course teaches 3 languages

    The first is NetLogo because its really awesome and you can do great things with it very easily. Ever try to simulate the spread of diseases in a C program??? The second is Dr Scheme which is a newer form of LISP. Teaches kids how to use functions and recursion. And the tortures of syntax. I just love () now. Rather i love (((()))) now. That portion of the course is concluded by us making our own number system with simple arithmetic functions. I think we used A's to represent a unit. Finally we conclude with Python. Basically it teaches us how to use a liner programming language.(none of the others really read top to bottom.) Overall a very good course. They also teach an introductory course that spends a whole term on python. Python has everything the more advanced languages have and its free in everyway. Plus it is much easier to read and teach with. I love it as does everyone who takes the course.

  36. Re:Why Python is good at our university by Anonymous Coward · · Score: 2, Insightful

    Unless ur an embedded applications developer/kernel hacker/lean and mean ....u can live ur whole programming life in ignorant bliss behind the facade that is the class library.

    this of course coming from somebody who uses "u" and "ur"...

  37. Re:I see whitespace is still syntactically relevan by golan · · Score: 2, Informative
    Well, It is said in the linux source code documentation. I know, it's C, but it simply says in /usr/src/linux/Documentation/CodingStyle:
    [...]
    Rationale: The whole idea behind indentation is to clearly define where
    a block of control starts and ends. Especially when you've been looking
    at your screen for 20 straight hours, you'll find it a lot easier to see
    how the indentation works if you have large indentations.

    Now, some people will claim that having 8-character indentations makes
    the code move too far to the right, and makes it hard to read on a
    80-character terminal screen. The answer to that is that if you need
    more than 3 levels of indentation, you're screwed anyway, and should fix
    your program.
    [...]

    So, listen to the masters ;-). I suppose this piece of advice is worth noting in python too, well, at least the force indentation...
  38. Re:Bastion disabled by samih · · Score: 3, Informative

    The new introspection facilities introduced in version 2.2 allow one to go around Bastion and rexec restrictions.

  39. Re:Why Python is good at our university by kruntiform · · Score: 2, Insightful

    Dijkstra was half joking, trolling even, in that remark about Basic. In the same piece are other hyperbolic comments such as "The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offence." Have you really read any Dijkstra? He always seems level headed to me. Your rant seems to be about a different kind of person entirely. Are you seriously suggesting he should have been defending the status quo of Basic (and Fortran and Cobol)? That Basic is effective? If someone tells you goto is harmful, by all means try it out yourself, but also go and read the careful reasoning behind that little quote.

  40. Re:Notebook? by costas · · Score: 2, Informative

    Google for IPython, it does some of what you want and a lot more.

  41. Python is actually strongly typed. by XNormal · · Score: 4, Informative

    Python is definitely not typeless. It's actually strongly typed. But it uses dynamic typing.

    Take a look at this article for clarification on typing models.

    --
    Stop worrying about the risks of nuclear power and start worrying about the risks of not using nuclear power.
  42. Beginners MUST learn C by duck_prime · · Score: 2, Insightful
    It could be worse, people could be learning Basic instead of Pascal and Java. At least they are slightly similar to C. I start programming with Basic and it's haunted me ever since.
    I have to weigh in here... it is my sincere belief that it is a huge mistake to start students in on high-level languages. If you start by learning that the JVM or the interpreter will "take care of it for you", it gives poor incentive to write carefully, with the real machine limits in mind.

    I suggest that all students be forced to learn C and assembler first, to get an idea of what's really, really going on under the hood. Students need to build moral fiber by implementing Yet Another Linked List, by tracking down memory leaks, and going through the agony of allocating a multi-dimensional array.

    After this experience, they will:
    a) Appreciate the glories of Java, Perl & co.
    b) Realize that even with memory-managed platforms memory is still a limited resource, and that leaks can still happen.
    c) Be able to harrumph at the next generation for forgetting what programming to the bare metal is all about.

    Hey I've gotta run, my dad is waving some IBM punch-cards and a soldering iron at me.
  43. The real way to get some head and tail by sblack · · Score: 2, Informative

    Not to nitpick but the correct way to reference the head and tail of a list in Python is as follows: head = list[0] tail = list[-1] Please don't defile this beautiful language by posting incorrect code snippets.

    1. Re:The real way to get some head and tail by ameoba · · Score: 3, Informative

      list[-1] is the last item in the list. To anyone coming from a functional programming background (such as lisp), the head of the list is the first element and the tail is everything else.

      Lisp style cons lists are essentially a big nested set of tuples

      [1, 2, 3, 4, 5]

      translates to

      (1, (2, (3, (4, (5, _)))))

      so head (the lisp CAR) is the first element of this two item tuple, tail (lisp's CDR) is the 2nd element, or the rest of the list.

      --
      my sig's at the bottom of the page.