views:

481

answers:

8

Once you have learned the basic commands in Python, you are often able to solve most programming problem you face. But the way in which this is done is not really Python-ic. What is common is to use the classical c++ or Java mentality to solve problems. But Python is more than that. It has functional programming incorporated; many libraries available; object oriented, and its own ways. In short there are often better, shorter, faster, more elegant ways to the same thing.

It is a little bit like learning a new language. First you learn the words and the grammar, but then you need to get fluent.

Once you have learned the language, how do you get fluent in Python? How have you done it? What books mostly helped?

+8  A: 

Have you read the Python Cookbook? It's a pretty good source for Pythonic.

Plus you'll find much more from Alex Martelli on Stack Overflow.

Jon-Eric
+8  A: 

Read other people's code. Write some of your own code. Repeat for a year or two.

Study the Python documentation and learn the built-in modules.

Read Python in a Nutshell.

Subscribe your RSS reader to the Python tag on Stack Overflow.

FogleBird
+2  A: 

I guess becoming fluent in any programming language is the same as becoming fluent in a spoken/written language. You do that by speaking and listening to the language, a lot.

So my advice is to do some projects using python, and you will soon become fluent in it. You can complement this by reading other people's code who are more experienced in the language to see how they solve certain problems.

Tomh
+3  A: 

The same way you get fluent in any language - program a lot.

I'd recommend working on a project (hopefully something you'll actually use later). While working on the project, every time you need some basic piece of functionality, try writing it yourself, and then checking online how other people did it.

This both lets you learn how to actually get stuff done in Python, but will also allow you to see what are the "Pythonic" counterparts to common coding cases.

Edan Maor
+3  A: 

There are some Python textbooks that not only teach you the language, they teach you the philosophy of the language (why it is the way it is) and teach you common idioms. I learned from the book Learning Python by Mark Lutz and I recommend it.

If you already know the basics of the language, you can Google search for "Python idioms" and you will find some gems. Here are a few:

http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html

http://docs.python.org/dev/howto/doanddont.html

http://jaynes.colorado.edu/PythonIdioms.html

If you read some good Python code and get a feel for why it was written the way it was, you can learn some cool things. Here is a recent discussion of modules worth reading to improve your Pythonic coding skills.

Good luck!

EDIT: Oh, I should add: +1 for Python Cookbook and Alex Martelli. I didn't mention these because Jon-Eric already did.

steveha
+3  A: 

More Pythonic? Start with a simple import.

import this

And add practice.

Alex
+6  A: 

I can tell you what I've done.

  1. Idiomatic Python
  2. Bookmark SO with the python keyword.
  3. Read other's good python code.
  4. The Python Challenge

That order is probably good, too. This is where things get fun.

vgm64
Hello, and thanks. Does SO stand for stackoverflow? "3. Read other's good python code." any other source except the ones being proposed in the other answer?
Pietro Speroni
+10 (if I could) for David Goodger's "Idiomatic Python" ref! I've never read it before, but it is full of gems - learn these and Pythonic your code will become. (Yes, SO is "stackoverflow".)
Paul McGuire
I know a very pythonic python programmers and very C++ python programmers. "Good" was a poor choice to express for the former!
vgm64
+2  A: 

Read existing projects known for technical excelence.

Some of the ones I'd recommend are:

voyager