Sunday, August 30, 2009

My Personal take Python 31 on Windows

Downloaded and installed Python 3.1 on Windows to kick around the tyres a bit on the new version of Python. Currently I am getting myself used to one of the biggest changes where print is now a function. This means that stuff like this:

print "testing"

will not work anymore. This will now give you an error :


>>> print "testing"
File "", line 1
print "testing"
^
SyntaxError: invalid syntax


The help function has also been made a function. This means that ....

help will not work too and will just end up ...



>>> help print()
File "", line 1
help print()


Now you will have to put up the parentheses like so ... help(print)

The map function will also not work like it used to. I am still trying to find out how it works.



>>> def print_me(line):
... print (line)
...
>>> print_me("stuff")
stuff
>>> a = ["print","me","now"]
>>> map(print_me,a)
map object at 0x01765CD0



These means too most of my code would be borked .. sigh! Stuff that I have been using for my client's code like Django and Zope will need to be updated too. This is all I have explored for now. Will write more as I encounter more.

Update: I updated the title a bit after the first comment. Tsk tsk some people can so be so uptight these days.

2 comments:

Unknown said...

> Currently I am getting myself used to one of the biggest changes where print is now a function.

That's pretty well known.

> The help function has also been made a function.

I don't recall "help" ever not being a function. In 2.5, your example (using an actual function rather than print) throws a SyntaxError (furthermore you're calling print, so you're asking for the help on the result of print, which should be None. Not exactly useful).

And re `map`, it's now a "view", so it's evaluated lazily (akin to the now-defunct itertools.imap in 2.x). If you were using `map` to generate side-effects (such as printing stuff), you were Doing It Wrong in the first place.

Anyway so far I must say I don't see the point of your post: everything you're discovering is clearly written in What's New in Python 3.0 (With print is a function being the very first item and map returning an iterator being part of the second one) and (for your future discoveries) What's New in Python 3.1.

Python 3.x is a significant break from 2.x, so you really should read at least those two documents unless you like wasting your time.

Finally, "Stuff that I have been using for my client's code like Django and Zope will need to be updated too." given neither Django nor Zope are 3.x-compatible at the moment, there's nothing to update for now. I don't know what Zope's timeline is (if any), as far as I know Django doesn't expect getting their Python 3.0 efforts started in earnest before Django 1.4 is released some time between 2010 and 2011 (they're going stop supporting one Python version per Django release, so Django 1.2 will only support Python >= 2.4, 1.3 will only support Python >= 2.5 and 1.4 will only support Python >= 2.6, at which point they'll be able to use tools such as 2to3 far more easily)

lowkster said...

Masklinn: This is my personal take on Python 3.1. Been aching to try it on for a while. I know that the docs already cover it. The post is not meant to replace or add on to it. Just as a place to record how I feel about Python 3.1. Thank you very much for the long comment.