python3 programming for novices

Kent Borg kentborg at borg.org
Fri Dec 24 15:06:01 UTC 2010


Python 2 vs Python 3: Python 3 is a better language, it is the future, 
but as you discovered, the libraries have not been updated.

So I suggest you try to program as much as possible in a Python 
3-style.  Some things work in both, so when you can do it the Python 3 
way and Python 2 will work, too.  For example, use "print(some, 
parameters)" not "print some parameters"; and use "!=" instead of "<>".

Python 3 was a compatibility break so there are some things that are 
incompatible between the two, a tool that might help is "2to3", which 
will make an /attempt/ at automatically converting from Python 2 to 
Python 3.  However, if you program with 2to3 in mind and it can work 
just fine.  So program with your fingers in Python 2 but your head in 
Python 3, once the libraries catch up, 2to3 will do the hard work.

I think there are no problems with having both Python 2 and Python 3 
installed at the same time on Ubuntu.  Keep Python 3 around so you can 
still play with it and not forget the future.

A final old-fashioned recommendation: the interactive text console of 
Python is a great way to play with it.  When I am messing with a new 
library I will use an interactive session to get the hang of how it 
works.  And once I am rolling I still go back to an interactive session 
to make sure I am getting some detail right in isolation before I drop 
it into the source code.

I haven't done much Python in the last few months, but I really like the 
language.  It seems that if, while pinning down an exact understanding 
of the problem, I can "take notes" in Python, collecting code fragments 
that solve portions of the problem.  By the time I really know what I am 
doing, sometimes the program is nearly written.  Then as I pull it 
together I naturally have to fix stupid little typos and syntax 
errors...but by the time I have cleaned up the easy stuff, I nearly have 
a working program.


Have fun!

-kb

P.S.  And Merry Christmas.





More information about the ubuntu-users mailing list