I'm an avid programmer, and I like to learn new languages. I normally teach them myself.
Python [1] isn't a "must-learn" language for me, but, as I work with Ubuntu [2], and a lot of their own code is now Python based, it'd be useful for me to learn, so that I can work with their code. I already know the basics of programming (and the advanced) and am versed in multiple programming Languages.
What are your suggestions for resources for learning Python, or how would you start working with Python to get yourself to a competent level with it?
The best way to learn Python (or any programming language) is to pick something you want to do and start doing it in the language you want to learn.
Pick anything that interests you and is slightly more complex then a simple Hello World. IRC [1] bots are a good project, as are most small games like Snake [2], Tetris [3], etc.
For Python there exists a wealth of information both online and in dead tree form:
Learn it the way you learn any other language. Write a program in it. Any program. Some program that is interesting to YOU. Doesn't have to be a huge project, but it should be a couple hundred lines of code. Something more than "Hello World".
No reason to try and "learn Python" unless you have some specific goal. Rather take the goal, and apply Python to it.
What will you end up with? Most likely you will end up with "C in Python" or "Java in Python", or "FORTRAN in Python". That is, whatever language you're comfortable with now will influence how you write your early Python programs. "When I want to do X in language L, I do Q. How do I do Q in Python." Which completely side steps whether doing Q in Python is a good idea in the first place.
In the end you won't be creating "idiomatic" Python code, rather you'll create working Python code, using idioms and constructs that YOU are already comfortable with while at the same time learning the Python runtime, syntax, and other boiler plate that surrounds a language.
At the same time, inevitably, some Python idioms will "sneak" their way in to your code. It can't be helped. This casual exposure of system to your way of thinking is what makes it easier to apply, because you're applying the new constructs in a domain you're familiar with.
Now, once you've finished your first project, you can start your second. Only now the fundamentals of Python are much more clear to you. In the second project, the fundamentals become second nature and now you can try and stretch to create "idiomatic" Python. Basically, now you can write "Python in Python".
Inevitably, later, when you go back to some other language, you may start trying to write "Python in Java", or something similar. Some will take, some won't. Some will be very difficult and not worth the effort, other effects may surprise you.
But starting blind, with just a language book, for me, had never worked well. I know how to program, I just need to know how to program in the L language. Rather than starting from scratch, apply the knowledge you already have and you'll end up have quicker success in the short term, and a better foundation to really learn the language in the long term.
The official tutorial [1] is great, as is Dive into Python [2]. However, I taught myself by writing an IRC bot.
[1] http://docs.python.org/tut/Dive into Python as well. It's already present in Ubuntu 8.04 [1] (Hardy Heron) installations, so it's very convenient.
The Python Challenge [2] is a very pleasant way to get used to programming with Python. You also get to try some quirky puzzles, so it's quite enjoyable.
[1] http://en.wikipedia.org/wiki/List_of_Ubuntu_releases#Ubuntu_8.04_LTS_.28Hardy_Heron.29I learned Python by doing lots of small projects. See Building Skills in Python [1] for lots and lots of exercises.
[1] http://homepage.mac.com/s_lott/books/python.htmlA lot of our users say that our ShowMeDo Python [1] tutorials are very helpful. There are 355 videos as I write this, with more open-source tutorials added each week.
All sorts of topics are covered, Python code is written and discussed whilst you watch leading you up to working examples.
Disclaimer - I'm a co-founder of ShowMeDo.
[1] http://showmedo.com/videos/pythonWell, there are great resources for advanced Python programming:
Here is a list of subjects you must understand if you want to master Python:
They are what make Python such a cool language (with the standard library of course, that I keep discovering everyday).
[1] http://en.wikipedia.org/wiki/Amazon.comMy daughter was a TA [1] at MIT [2] for a introduction computer class that used Python. I worked through their weekly programming assignments.
Here is a link that has the course's assignments for the semester before my daughter TA'd it.
6.00 Introduction to Computer Science and Programming [3]
[1] http://en.wikipedia.org/wiki/Teaching_assistantPython In A Nutshell [1], by Alex Martelli. For an experienced programmer this is the best way, IMHO. Good, compact, to the point. In Martelli's case, pretty well written, too.
[1] http://rads.stackoverflow.com/amzn/click/0596100469I agree with William Keller; use the tutorial to get your feet wet (it's short) and then read Dive Into Python or a Book, whichever works for you, as you begin your own project. At first, just to get the hang of the Pythonic style of doing things, check out all the great projects tagged with Python at Google OSS project hosting [1].
If you get stuck, you can normally get answers within seconds at the Python IRC channel [2] on freenode.
[1] http://code.google.com/hosting/search?q=label:PythonOne of the standard recommendations over on Freenode's #python is:
Think Python: An Introduction to Software Design http://www.greenteapress.com/thinkpython/thinkpython.html
It's free, comprehensive, has lots of exercises, and tries to teach the Python mindset as well as the syntax.
Some free programming books in Python [1]
Two others:
NLTK Book [2] - Natural Language Processing using Python
Invent Your Own Computer Games With Python [3] - a kid-focused book on implementing Tic-tac-toe and other simple console based games. Very readable and easy even for an inexperienced programmer.
[1] http://www.freeprogrammingresources.com/pythonbook.htmlLurk on the Usenet group for Python: Google groups [1]. Lots of interesting topics and good explanations.
Another nice resource is the Daily Python URL Daily Python URL [2]
[1] http://groups.google.com/group/comp.lang.python/topicsAs mentioned, find some interesting problems (small is better), and jump in.
As one resource (for any language), Project Euler [1] might inspire with some neat problems.
Another idea is to implement some of the classic data structures (e.g. Red-Black tree, or a priority queue).
I have come to love Python but won't deny that there were some frustrations at the start, as with any language. However, I do think that it is fairly easy to "get" the Python philosophy, because it is so intuitive and fluid. It may take time to become truly Pythonic but it doesn't take long to ask "which is closer to the Pythonic ideal: solution A or solution B?"
[1] http://projecteuler.net/The book I used was Core Python Programming by Wesley J Chun. I believe it is a second edition now. I really liked it. I also have the Python Cookbook for a reference on how do specific tasks. The python library documentation is also really helpful. The best online community I found is the Python usenet group comp.lang.python.
I found the official tutorial to be sufficient. After that, I've only needed to refer to the library reference. Once the Pythonic way of doing things sinks in--and it really is intuitive, which is what makes the language such a joy to use--you find you don't need additional coaching.
I entered the PyWeek [1] competition. There are countless examples of working Python code for making games at pygame.org [2]. All the games from previous PyWeek entries are available with source code on the webpage, too. I learned a lot from looking at some of those entries. Having the time limitation encourages you to dig in, solve problems, and learn Python basics.
[1] http://pyweek.org/I don't think Python really requires reading anything at all, just think of something you want to do and do it in Python. When you hit a brick wall, search the documentation.
I'm not saying that the official documentation is helpful at all, but they help you piece together what you're trying to do.
Anyway, that's how I learned my share of Python, albeit a small one.
I've been going through this process recently and have found that beyond the following books, #python on irc.freenode.org to be very helpful.
I use both books, while they're both similar, they touch on topics in slightly different ways.
I have found the best way to learn is to pick an application idea and bang my head against it with the various resources until I get it to where I want it. If it's something I plan on releasing with an open license, I've found asking #python on freenode to do code review as very helpful and enlightening. Good luck!
I decided I wanted to create an RPG based on an old pen and paper game, but I didn't like dealing with the idiosyncracies of C/C++. I had heard that Python was a good language so I decided to learn Python so I could write the game.
If you don't have a real need to learn a language, it will be difficult. Though it's old (Python 2.2), I would recommend getting a copy of Dietel & Dietel's "Python How to Program" book. It's structured like a college text book so it provides many different types of programs to write, from simple scripts to actual "real world" programs.
http://www.projecteuler.net/
Project Euler is a great place to practice programming. It is a site full of math/programming problems, and Python is a great language to use to solve them. I got significantly better at python by using project euler.
I used the book 'Dive into Python' while learning, and I think it's a good one for experienced programmers. But recently I have found Google's Python Class [1] which should be very helpful for beginners.
[1] http://code.google.com/edu/languages/google-python-class/index.htmlDive into Python and by looking at other people's code.
I am currently implementing Conway's Game of Life [1]. It's pretty cool because it forces me to try some GUI packs for Python at the same time.
[1] http://en.wikipedia.org/wiki/Conway%27s_Game_of_LifeI learnt the basics from Programming Python by Mark Lutz. Then I spent a few years programming Python in my day jobs.
While i did read random chapters from a variety of books, most of what I learned was from the sourcecode of various frameworks (i.e. Django, Twisted). One of the greatest things about Python is that code is easy to digest 99% of the times.
Stanford School of Engineering has some free lectures that go over some Python: Introduction to Computer Science | Programming Paradigms [1]
Lectures 24+
[1] http://see.stanford.edu/see/lecturelist.aspx?coll=2d712634-2bf1-4b55-9a3a-ca9d470755eeAnother vote for Dive Into Python here! What I most appreciate about it is that it goes beyond merely teaching you the syntax, to teaching you the basic "idioms" of Python programming so that you can write code in a style that is efficient and Pythonic.
After you've mastered that, O'Reilly's Programming Python is an excellent, excellent reference and guide to all the cool things you can do with Python, especially web and database programming.
I have learnt Python while trying to do the right thing with other languages.
I've found A Byte of Python [1] by Swaroop C H, to be the most useful resource in laying out and explaining the fundamentals of Python in terms that mortals can understand.
[1] http://www.swaroopch.com/notes/Python_en:Table_of_ContentsNo Internet connection, and the Python.org Tutorial.pdf [1].
[1] http://docs.python.org/download.htmlI'm currently attempting to complete Project Euler [1] in Python. So far I've completed the first three, and learnt Python's methods of ranges, for statements, variable assignment, bool logic, output, loops, indentation nazi-ism, and commenting.
I come from a heavy Java/database background, and I'm sure I could do a lot of the Euler problems in Java, PL/SQL or Excel, given I know programming structures and problem solving, but I want to challenge myself with a new language.
It's like trying to converse to someone in French even though you know a lot of English, and they know English and French.
[1] http://en.wikipedia.org/wiki/Project_EulerWell, to put in a blatant plug, I'm writing a Intro to Programming book [1] using Python. It's an ebook and will be free, if cost is a concern.
[1] http://python-ebook.blogspot.com