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."
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
Subcribers can't reply any sooner than non-subscribers
"I'd rather be a lightning rod than a seismometer." -Ken Kesey
from what I understand, comments can't be posted until it goes live to the general public
Python is interesting experiment. In our computer programming classes we allow student to pick two language to major in. One must be choice of proper establish language like C , C++ , Perl, etc and other must be modern experimental choice like Python , Java , etc. Python has become most popular choice for second language at University, and I'm not sure why!
One good thing is that there now unicode file support for windows which was a big annoyance to the student before. Now they can actual code in Chinese and save files in Chinese names...
Another good point for international user is.. universal new line support which mean Python can now support Chinese newlines as well as American ones. Bravo Python team. A much more international liked language is coming along!
-- Dr. Fu Ling-Yu, Internal Technology Consult; Tongji University, People Republic of China.
In 3... 2... 1...
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?
Skip the upgrade and switch to Ruby.
There's a feature I'd like to see removed.
I guess it's Guido's way of just being different.
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!)
Seems the new release suffers from a certain DDoS bug.
You can tell if someone is a subscriber or not if they have an asterisk next to their user number. If you look at any given article you will notice quite a few subscribers.
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.
There's a feature I'd like to see removed.
Why ? What would the benefit be, beside breaking all existing python code ?
Heh... another useful book just sprang to mind, try Learning Python. There isn't really much between the two books... although a see Amazon offer a discount, wheras with the other one you don't get a discount... anyways your choice :)
I have over 70 freaks, do you?
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.
Sounds like a Vlassic picle. More crunch.
Not, necessarily from this particular release, but in general the whole objective/functional thing which Python is doing really is very interesting and ought to be pushed further.
Some way to use Perl libraries would really kick ass too but I guess that's impossible without Parrot coming into reality.
Hexayurt - open source refugee shelter,
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
I literally just bought that today... I'm not joking... I have started to do some code in Python and had found other Nutshell books usefull in the past.. And Python in a nutshell is living up to the expectations...
On Arrakis: early worm gets the bird. Magister mundi sum!
You mean like how using different editors which implement tabs differently (vi and Emacs both have settable tab spacing) already breaks Python scripts that must be worked on by more than a single developer?
Or is Python simply not ready for important work?
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?
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
I dislike trolling (as I assume this post will be modded) however, the misspelling of the word "definitely" has begun to irk me greatly. As a high school student who sometimes has to view the writing of my peers, I have to lower my expected standards. But when I go to read /. I'd assume that The-ones-who-post-stories-from-on-high might be able to spell check their commentary. Thank you for listening to my grammar rant.
.
why does the porridge bird lay his eggs in the air?
native bytecode ? Anyone know about this ?
Use spaces, not tabs, like all the other python programmers I know.
And Emacs' python-mode deals with the situation appropriately.
Maybe for those who know Python it's faster, but that's no different than any other language: programmers work faster and better in familiar languages.
Maresex support in 2.3 (Score:0, Informative)
Friends don't let friends let trolls use their mod points.
Mind telling us in a diary or future post how much you were able to get from the referrer? Just curious, I'm thinking of testing this out myself.
unless the story was posted by timothy, and it takes half an hour for him to unclick the "archived" button.
Do you even lift?
These aren't the 'roids you're looking for.
> If you look at any given article you will notice quite a few subscribers.
:^)
No, I think you're just rationalizing so you feel better over having tossed out your hard earned money on a lame-assed subscription.
HAND.
All the Python developers I know use tabs. It saves keystrokes, ya know.
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: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.
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.
-
TABS and order of whitespace
- 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.
Other than those rare or obscure issues, I can't think of any reason that mandatory whitespacing should hold someone back from python.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).
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]?
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.
make world, not war
unconvincing grammar flaws and, really, come on, almost nobody from china writes english with perfect capitalization and punctuation unless it's a business communication and their english is damn good already (better than what you were faking).
... but that was intentional.
oh, and then there's the name
Isn't that better?
No cookie for you.
At one time people were really concerned with the whitespace situation in Python. While both sides made good arguments for and against having whitespace be syntactically important, it all boiled down to van Rossum's decision to make it so.
Then came the trolls. Lots of them. They saw that there could be bites to be had by just dangling the topic of whitespace out there. People were very willing to bite on the old arguments, but nothing was ever decided because all the arguments were just rehashes and the "experts" still saw mandatory whitespace as a crutch for stupid programmers, and Python "experts" said it helped them see where their blocks were. It didn't matter a whit, Guido went his own way.
But now, time has passed and Python's reliance on code beautifiers just to run has shown itself to be not quite the boon that it once purported to be. Yet Python enthusiasts still cling to the idea that whitespace ought to be syntactically relevant. So out come the old arguments, only this time the anti-whitespace crowd has more ammunition and the pro-whitespace gang is running out of bullets. But Guido goes his own way.
At some point the Python project will need to fork to release it from this whitespace requirement. In this day and age, only beginning programmers need such a visual crutch. Python has shown itself to be useful beyond Hello Worlds and Good Morning %s! It is time for the language to grow up. Too bad Guido still goes his own way.
It saves keystrokes, ya know.
You seriously think that programmers who use spaces for tabs are hitting the space bar 2, 4, or 8 times every time they indent? Lemme guess, you code using Notepad, right?
Both features he claims will help programming in chinese do no such thing! Unicode files and (script) file names are already supported (the new feature improves handling of unicode names within python), and universal newline support just means you don't have to convert from windows to *nix carriage returns.
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
The normal python compiler compiles to portable bytecode. I think you need some software that translate that to native (machine) code. It is called psyco, hosted on sourceforge.net. I don't know about its current status though.
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.
Easy example:
Let's say you have a decent sized block, 15 lines or so.
You are typing them in and get to line 12 when someone pulls the firealarm and you and everyone else has to go outside.
You come back in and type in those last 3 lines, but you forgot the indentation because the firealarm has completely broken your train of thought.
Run the program: lots of errors and possible data corruption.
With a normal language that uses bracketing enclosures (parens, brackets, etc), you will not be able to run the program. The compiler will croak on the missing closing bracket. No data is lost and language integrity is kept.
Whitespace relevancy makes programs less easy to read, and harder to program because it relies on the developer knowing where to indent or not, whereas a normal language that relies on opening and closing brackets enforces better programming style by simply not allowing unmatched braces. You are making the programmer work harder in Python, but making the computer do the work for you in other languages.
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.
haha youre funny, posting links to the gnome site, cleverly disguised as links to the KDE 3.1.3 update, which was, btw, released yesterday. Go troll elsewhere, moron.
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...)
Booleans in Python at last, hurrah. We should see Boolean support appear in Jython soon too then, and an end to fiddling with 0's and 1's.
The KDE project is famous for its funded and organised trolling of weblogs and message board associated with Linux and Free software/open source. Outrageous newbie impressing claims are made for the software and huge quanities of FUD are spread to destroy competitors
That's called astroturfing, not trolling.
I bet the next ask slashdot will be about having sex with mares!
Be sure all questions will be answered and the answers will be top quality! I may even post some interesting HOW-TOs, including unreleased so far Pleasuring-Mares-HOWTO. (just give me a server that will survive slashdotting to post relevant pictures!)
You don't seriously think that a tab/space/space is the same as tab/tab, do you?
That's the problem. Whitespace is INVISIBLE and there are MULTIPLE TYPES OF WHITESPACE. Relying on that kind of thing is dumb and blockheadish.
Luckily I don't have to work in the Python-using group. It's all Ruby for my team.
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
Buy Text Processing in Python
See,
http://www.bigwebmaster.com/752.html
for example. Or just Google for "fast-paced tutorial on the syntax"
TECHDIRT !Better than Slashdot,NO Gay Karma CENSORSHIP or LINUX [techdirt.com]
;)
Same mare trolls there though
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.
before i can get the new version after python.org is done with this slashdotting
post mirrors people!
vodka, straight up, thank you!
It would be nice if python had lists with a head and tail. It would also be nice if it had non sequential threads, a collector instead of reference counting, and maybe a decent attribute analysis so that the expression "a"[1] is barfed on before being
run.
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.
Here's another one:
eval'd code.
Eval'ing anything more than complex than simple, pre-formatted blocks of text is going to cause a headache. One of the great things about interpreted programs is their ability to morph through eval calls. Having to ensure that blocks of text you paste together in code are properly indented to be interpreted via eval has got to be LOADS of fun.
Alex Martelli has written an article that talks about the changes from Python 2.2 to 2.3.
David, thanks for making your book available on-line. I'll be sure to look for a 'dead tree' version.
My father is a blogger.
Some of these features look useful enough but the one that stands out most as having a minor problem is importing modules from zip archives. That's all well and dandy but why not also support from other archives? tar + gzip or bzip would get better compression. The syntax looks like it could be a little clearer. Why not just 'import example.zip/mymodule' instead of messing with sys.path.insert() ? That sounds cleaner to me.
At what price learning? At what cost wisdom? The price is a man's peace of mind, and the cost is his life.
Why asking? /. doesn't display karma points anyway and translation of moderation and stuff into karma points is quite obscure and hard to keep track of.
You need certain visit and post frequency (not too much, not too few) too if you want to get M1 points.
apt-get is missing what emerge is good at. (source packages, and yeah I know of apt-src)
emerge is missing what apt-get is good at. (binary packages)
If anything decimal shouldn't be there.
-Libertarian secular transhumanist
three, sir
Three!
In SOVIET RUSSIA... erm...NSA AMERICA, the Internet logs onto YOU!
You've been modded down -1 overrated because the link is a plug.
Regards,
your moderator
Pythoneers are spacers!
# vim: filetype=python ts=4 sw=4 et si
Yee ha!
That is good for us Python folks. You don't even understand whitespace. Ruby can have you.
Neither. They both suck.
ML kicks their asses!
http://maps.yahoo.com/py/maps.py?Pyt=Tmap&ed=2eq1M up_0TpxXa5UN63mjyUSVQJsX5Sk2q8YXq2EXTawW.mGFYV8AHt JOL7B4CsQWw--&csz=Washington+DC&country=us
(purposefully not anchored)
Computers are useless. They can only give you answers.
-- Pablo Picasso
http://saveie6.com/
My major object to whitespace instead of { and }, or similar, is that it makes generating code using XSLT an absolute nightmare. It may not be a big problem to other people but it is to me. Using { and } you don't have to worry about the indentation, which is a pain in the ass to get right with XSLT. For hand written code it's not a problem, any decent IDE, i.e. emacs, will solve the problem. For autogenerated code I think it's a real minus.
development.lombardi.com
Python is indeed getting closer. Just give them some more years to finish the last three itens and suddenly we'll have thousands more using a Really Good language.
:-)
Note to moderators: this is a troll
Suppose that you have a web service written in a programming language with associative arrays (C++, Awk, Perl, Python).
Suppose that an attacker analyzes your hash function and then sends you hand-crafted input that tickles the worst case.
Perl 5 has this problem (sorry, no link, perhaps someone will provide one). Perl 5.8.1 hacks around this by throwing some randomness into the hash function, which means that the "keys" and "values" operators change their order from one execution to the next.
So yeah, it *is* important to have good worst-case resource consumption, because if your code runs in public, a hostile person gets to pick the input.
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
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:
- ->somethingelse;
d e additions but not this. Dumb, IMO. /rant
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;
--
---->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-co
-Sean
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.
There are modules which allow you to use {} if you want to be an idiot ;)
An editor could easily be modified to show you a view of the code with {} if you wanted.
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.
easy solution.
while something someval: #{
do.something()
while x 10: #{
print x
#}
#}
TODO: Something witty here...
http://altis.pycs.net/stories/2003/04/16/whatIsPyt honAndWhyPython.html
Why the hell do people mod comments connected to ASCII trolls? No one will see them anyway, except for the people who've selected to mod up threads if comments are highly rated. So, to those idiots with mod points,; DON'T MOD THIS UP!!!
"A language that doesn't affect the way you think about programming, is not worth knowing" - Alan Perlis
You're so gonna get modded 'Offtopic' \o/
Do you have a reference?
It appears you are now the authority on who is and who is not who they are. Please look at my journal at Slashdot. A lot of people have been supportive.. but it seem that a lot of people mostly AMERICAN are more interested in taking their own vendetta against foreign people like the Chinese. This is international site and even though sometimes we are not all as good at English as AMERICAN we should get on with each other a bit better!
-- Dr. Fu Ling-Yu, Internal Technology Consult; Tongji University, People Republic of China.
As copyright owner of this comment, I authorize everyone to defeat any technological measure which limits access to it.
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//
I'm looking forward to playing with the datetime module. The old C-based API is just gross.
Actually it's not that difficult. You can build the block you want to evaluate as a string seperated by semi colons.
eg: while something: do_this(); do_that(); i += 1
Which is still bad, but not as bad as the program quietly operating incorrectly, which is still possible.
You are correct, I didn't think my answer/solution through fully. That said, I'm still not a fan of the whitespace requirement. It frustrates the heck out of me when I switch between vi and emacs on new/different systems.
-Sean
But often when a sophisticated bit of eval work is going on, you are loading the code from a file; a file that was hand-edited by a developer.
--Mike
"Not an actor, but he plays one on TV."
To quote the Python 2.3 release page:
Still a work in progress, but interesting.
Ciao
----
FB
Makefiles also require proper tabs for inputing rules.
Which is still bad, but...
Not particularly, as in Python you know not to do that. Myself, I have VIM macros for intenting and outcommenting and incommenting code in a wide variety of programming languages. What you are describing is what I call a "theoretical problem that does not turn out to be a problem in practice."
C//
On Guido's weblog you can read that he's made a wager on parrot's speed:
And let's not forget the opening lightning talk, which I presented together with Dan Sugalski: the Great Python Parrot Challenge. Dan believes that at OSCON 2004, Parrot will be able to execute Python bytecode faster than CPython can. I don't give him a chance. Dan bets me ten bucks, a round of drinks, and a pie at ten paces.
So the power of parrot against the regular python-interpreter-written-in-c. Nice wager, though!
Reinout van Rees
What's the user base of python and perl? Are they equal?
Are python and perl equivalent in speed?
I heard somewhere that perl is faster than java is that true?
I haven't kept up to date on this stuff since 1999 or 2000. (been mostly programming in c and c++ since then....)
What are the current stats?
So, listen to the masters
So do php people get pissed off that their language is never even considered in python/perl flamewars?
I guess I should have said 'DON'T MOD THIS AT ALL!!', man people are idiots.
"A language that doesn't affect the way you think about programming, is not worth knowing" - Alan Perlis
Does anyone know of a notebook interface for python as for Mathematica?
Running python in an emacs shell allows for erasing previous I/O but new input can only be added at the bottom, and old inputs can't be edited and rerun.
You should use sts=4 instead of ts=4. ts is best left to 8.
You don't seriously think that a tab/space/space is the same as tab/tab, do you?
Of course not. But as I understand (and as I do, and probably as the majority of Python programmers does), he meant that he only uses the tab key and the backspace key to indent his code. He has set up his editor so that there's only ONE TYPE OF WHITESPACE in his source files (":set expandtab" in Vim).
Besides, whitespace is not necessarily invisible. Using ":set list" in Vim can reveal the different types of whitespace in your file, and is very useful to spot trailing whitespaces, tabs and other problems.
No one will see them anyway, except for the people who've selected to mod up threads if comments are highly rated.
You overcomplicate maters. Some of us browse at -1 Nested, so we see all, know all. Fuck the moderators, I can filter my own content thanks.
So you use a kludgy hack to work around a deficiency in the language? Whats that about shooting yourself in the foot?
"Python : You attempt to shoot yourself in the foot, but you get the indentation wrong and graze your ankle instead."
Thats the point though; why can't Python at least have the option of using bracketed code blocks instead of requiring whitespace?
TABS and order of whitespace
Recommend practice is to use spaces exclusively. Any python aware editor will translate the tab key into the proper number of spaces. Mixing tabs and spaces can cause all kinds of problems, especially with cut and paste.
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.
Don't do that! The only reason to put that much stuff inline is speed; otherwise making it a method with a well chosen method name makes the program much easier to understand. And you wouldn't be using a language like Python if you were worried about getting the last bit of speed out of it, would you?
John Roth (too lazy to log in.)
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.
Yes, you too can use a half-baked lisp without admitting to yourself, with the new improved Python 2.3!
Remember, Greenspun's 10th is not just a rule, it's the LAW!
There is not a single decent anti-whitespace argument. The only one would be if you are using editors designed in the 1970s, and which didn't evolved, but 99.99% of people are not ; so it's stupid to make people type millions of totally useless and redondant ("start-block")/"end-block" indicators (and which would inflate line count by 25% in my last code), just to satisfy the needs of the 0.01% cavemen. In Python, what blocks you see is what you get, and that's how it should be.
It's an option. Put "end = 0" at the beginning of your code and you can write:
for i in range(10):
. . print i
end
But absolutly no Python programmer bothers. Guess why? Because it's a total non-issue.
For your second point, 10 levels of nesting is, IMHO, at least 7 too many. If you find yourself adding another level after three, it's probably time to look at your design.
This is the same kind of bullshit as saying goto is always evil.
You are correct, sir! Expandtab is what I was referring to, and I'm surprised that there are folks here who are ignorant of this feature that editors provide (not just vim, but it just so happens that I do use vim). I was hitting the tab key and having spaces inserted rather than a tab character even before I was a Python programmer.
What do you call "many new and updated modules have been added"? That by itself comprises many changes to the new Python.
Really?
emacs users probably have something similar.
All this said, I am of two minds regarding the whitespace -- enforced consistancy makes it a lot easier to decipher when reading at 3AM, but it means that the programmer has to do all the work when moving code around (ie there is little chance of there ever being a python equivilent to 'indent' or 'perltidy').
you should read everything on the internet as if it had "but I'm probably talking out of my ass" appended to it.
If my editor has tabwidth set to 2, then yes, tab/space/space is the same as tab/tab. But why would I be hitting the space key to indent anyway? I hit the tab key, and 2 (or 4, really, that's my setting) spaces are inserted. Wow, it's like, magic!
I use python a lot.
The one place that the whitespace-importantness of Python causes problems is if you've got scripts embedded in HTML pages. If you do this with Java or TCL the braces tell you where the blocks are. With python it gets confusing.
Other than that, python is, in the words of Mary Poppins, "practically perfect in every way".
-- ac at work
Check out guido's reponse to that exact question. Unit Test - "Everything"....
Anthony
Putting a large block of code into a while or for loop.
Do what you should be doing in any other braces-based language like C or Java -- refactor a big chunk of ugly code like this into its own private function or method and put an invocation of this method in the while loop instead. If you need to act on local variables, pass them into the function/method as parameters.
TABS and order of whitespace
When would you ever use both tabs and spaces in your whitespace in any other source code file? Some people standardize on tabs of a certain width (2, 4, or 8 chars), others such as myself standardize on spaces, but I never mix them up simply because I can't "see" the difference. All of my editors and IDEs are configured for this. (The official recommendation in the Python style guide is to use 4-space indentation, but this is not enforced.)
Also, there is an option that will generate warnings if you run the program using differing whitespace characters to let you know you've been bad.
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.
Again, if you find this to be the case, then you are not refactoring appropriately. Read Fowler's Refactoring and learn how to break up your code into more-manageable chunks (plus other great tips).
"First you gotta do the truffle shuffle."
This is a very simple test. As a matter of fact it is just a simple "Hello, World!" from each program.
Python = 2.3
Perl = 5.8.0
From a standing start on Windows XP:
Perl = Time: 0.245
Python = Time: 0.967
Is this because Python has a higher startup cost than Perl does?
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.
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.
My point still stands, though. You're going to see it anyway.
"A language that doesn't affect the way you think about programming, is not worth knowing" - Alan Perlis
I have my own indention procedures as well, but if I don't follow them precisely, my code doesn't gain unwanted "features" as a result.
Give Ruby a good, solid try folks, really. Python has NOTHING on Ruby, trust me.
A "reliance on code beautifiers just to run"? All you have to do is be aware of some whitespace issues, which aren't exactly "hard science", and use a decent editor (or use the one you prefer properly).
Yes, inexperienced programmers get confused when they hit the Tab key a few times and get actual "hard tabs" in their code, and their confusion continues when they use spaces to align things in a way that naive people use word processors like typewriters. But there's no substitute for knowing what the editor is putting into your file, and anyone who has to deal with non-ASCII characters will come up against a similar issue very quickly anyway. (Hint: which encoding are you using?)
The solution to tab/space mixes, which are the *only* danger in Python's use of whitespace: configure your editor properly or get your teacher to do it for you. My opinion is that if you're in the programming profession and don't know about such basic issues, then you should either learn more about them or start considering other lines of work.
And finally, as far as the "block delimiters are great - I have no problem with C code" argument is concerned, perhaps those who repeat this all the time have never seen what happens when code is passed around between editing environments. Try following the logical structure of a misformatted C/C++/Java program without tediously counting braces. Yes, it turns out that dodgy tab/space mixes are a real bummer for C/C++/Java maintenance (which is the part of the lifecycle where most programs spend their time anyway), so it isn't "just a Python problem" if you're programming in the real world.
Whitespace that doesn't reflect a program's structure is a bug waiting to happen.
In that case, {'s and begin's are just an annoyance that take up extra space in many indentation styles, and introduce a class of errors.
People say that whitespace significance introduces its own class of errors. However, I've been bitten multiple times by bad indentation and bad {'s, while I've not once been bitten by python's usage of whitespace.
The easy rule is, don't use spaces in your indentation - only use one tab per nesting level. That way the 3 columners can see things at 3 columns, and the 8 columners can see things at 8 columns, and everybody gets to see things the way they most like, all from the same code. If you mix in spaces, then you end up stuck with one tabstop width unless you use a software formatter like gnu indent (which gives some people fits).
Required whitespace is not a deficiency, is a feature. It's there for a reason. And if you don't like it, Perl is what you deserves.
I have my own indention procedures as well, but if I don't follow them precisely, my code doesn't gain unwanted "features" as a result.
"In theory, there is no difference between theory in practice, but in practice there is."
Sir, I have never had a python program gain "unwanted features" using the *theoretical* weakness that you believe exists. Further, I would assert that this problem seldom ever actually arises, amongst beginners and experienced Python coders alike.
C//
I believe you. But I don't believe I would be as lucky.
Between whitespace problems and my fear of whitespace problems, I don't know which is worse. Even if, in actuality, there were NO whitespace issues at all, my reasoned fear that there are is just too much stress to have while programming.
I liked everything I have heard about Python, except for that one thing, and it's too much to overlook.
Your sole point is that a "miss tabbed document" (sic) breaks the code. Could you explain where this altered tabbing comes from? Would you similarly deride a language for not being impervious to random removal of characters?
I've written 10's of thousands of lines of Python code and have never had (that I can recall) a single problem with indentation, blocking or scope. I must admit, I had exactly the same knee-jerk reaction to Python as you before actually trying it -- it took all of one day of using it to wash away any doubts. This is after years of coding C++ and Java, BTW.
Side note: if you're terminating lines with a semicolon in Python then I doubt you "use it alot" (sic).
This was my feeling for years, before I picked up Python. Your fear is an irrational fear. The only legitimate problem I've run into with python programs are when functions get very long, and you'd like to quickly jump from begin-to-end of scope (or vice-versa). While a python-aware editor could do this for you, I don't use one, will never use one, and so have to occasionally tolerate that annoyance. Usually it's a good sign that the function needs to be refactored a bit, but so it is.
:)
And the white space problems aren't as extant as most people think. For example, in Python, this is legal:
>>> a = [
1,
2,
3,
]
>>> a
[1, 2, 3]
>>>
Note that Python, at cetain points, actually becomes white space (newline/indent) *insensitive*. As it turns out, it does so at all the places where you might want it to.
Python is about the most readable programming language ever written. That's saying a lot for it, and implies something about how it handles white space as well. For one, your eye is not overloaded with tons of symbols as it might be in, say, Perl.
C//
What if you had to retab a large block of code because you added another while, an if statement, or a handler? Where do you stop tabbing? Also, have you ever tried editing python code in vi and emacs? It doesn't work with default settings. Your statement, however, is the perfect example of why this annoys me. You simply wipe your table clean by saying it isn't important. It *obviously* is important or it wouldn't have hung around this long...
-Sean
The fear probably is irrational, I can't argue that because I ran away from Python before I really found out. I have to admit that I'm just too much of a Ruby fan to even want to address the issue.
Can't speak for emacs, but vi works with python fine. Sure on the default settings vi (and vim) insert a mix of spaces and tabs, but the editor does so consistently, and that doesn't cause any problems for python. Using non-default settings, such as 'set et' in vim, will eliminate even this slight danger, what's your problem about using non-default settings in your editor btw. You have set ai, haven't you?
As far as moving larger blocks of code, the easiest way in vi, is just to issue an ex command, for example ':4,15 >'
When I first used python I thought the whitespace thang was going to be a big issue. Now I get pissed off using those antique brace delimited languages.
Strangely, many of the world's preeminent CompSci institutions disagree one hundred and ten percent. At MIT, the CompSci curriculum begins with--and throughout remains heavy influenced by--Scheme. Why? Because hardware changes. Because the things you learn about computers by programming in C are really limited (not every computer is a register-based machine). Because learning how a specific computer works doesn't teach you bupkis about how computation works.
... etc., etc., etc.
For that you need a formal model of computation. There are two principal formal models of computation: there's the Turing Machine and there's the Lambda Calculus. We don't have very many languages with explicit support for Turingisms. On the other hand, we've got several languages with explicit support for Lambda--from LISP and Scheme to ML and
First learn about computation. Then learn about how to apply computational theory to a specific architecture.
That's the way MIT, Stanford, et al. are teaching CompSci nowadays. That's the way I was taught CompSci at the university level--our Intro to CS course was taught in Pascal (yes, I went to college that long ago), mainly because of demands that students learn something "practical" in CS141, but as soon as you got past Intro it was heavy on functional languages and lambda.
I wholeheartedly endorse it.
I have read a number of books on python over the years. Last year I bought 'Python Programming Patterns'. I would strongly recommend this book to anyone who is already experienced in programming. It literally goes into very deep detail about many many features of the language.
He has later retracted his statement, but it is not positive.
And this post sums up what Ruby thinks of Bruce :-)
A language that needs a particular editor is broken.
Confucius say, "Find worm in apple - bad. Find half a worm - worse."
Yeah, and a language which requires all 26 letters of roman alphabet is broken. Why don't we stick with just 0 and 1? This is back-compatible with punch-cards, mister caveman.
OK, I'll make this simple so that the logic is completely transparent:
In Java, program structure is defined by the programmer inserting appropriate "{"s and "}"s. Indentation can be implicitly determined by the editor based on this structure.
In Python, program structure is defined by the programmer inserting appropriate indentation. (If you wanted to), "{"s and "}"s could be implicitly determined by the editor based on this structure.
Your argument is that, with Python, an editor cannot magically retab the document as it can with Java. An equivalent statement would be to deride Java based on the fact that an editor cannot magically insert (redundant) "{"'s and "}"'s based on the indentation as it could in Python.
You ask "where do you stop tabbing?" after inserting an if statement. The answer, of course, is that in all languages, creating a new block is changing the structure. In Java, you do this by inserting your braces. In Python, you do this by changing the indentation. Your question is really: "how does an editor determine this implicit presentation based on the structure given by the programmer?". In Python they are the same thing so the answer is trivial.
To answer your question: I've exclusively used emacs as my Python editor for several years and have never touched any emacs settings w.r.t. Python.