Py3K, what to look for in brief

This article was referenced by Guido in the Python-Dev indicating certain interests from academic community.

Actually thats a good article summarizing what to look for in Py3k.

1) Simpler built-in types.
Instead of having a built-in type for int and then for long as in Py26, have a single built-in type int in py3k, which will behave like long and serve for int as well.

2) In py26, you and str and unicode. Now Its just str, which is internally unicode. So all strings are unicode in py3k.
There is a separate bytes type for bytes of characters.

3) 1/5 will be 0.2 in Python3k. If you want the result to be 0, like in Python26, do 1//5

4) No comparisons supported between incompatible types. Documents from time immemorial advised the users to not to rely and it can change anytime. Well the change has happened.

5) its print() function for output now, just like input() function input.
Two things here. Previously in py2x, input() expected an object and raw_input() was actually used to input. Now in py3k, its just input() which will behave just like raw_input() before.

And in py2x, print was a statement, now its a function.
The article mentioned at the start gives a good rationale.

All you have do is, as soon as you type print, your fingers should automatically now get used to typing ( and proceed with what you were doing. More details on print function in py3k can be found in docs.

6) Everything is a new style class. All classes that you define will implicitly be derived from the object class.


7) There is refactoring tool developed by python hackers which can be used to port your py2x code to py3k. Everyones resounding advice is Use It!. This will help in migration as well fix any issues with the refactoring tool.

No comments: