views:

5157

answers:

14

Hi all,

I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been a the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solutions and also with the semantics of the language that allows such a natural flow from thoughts to workable code.

What I would like to know is your answer to a kind of question I have seldom seen in this or other forums. This question seems central to me for anyone on the path to Python improvement but who wonders what his next steps should be.

Let me sum up what I do NOT want to ask first ;)

  • I don't want to know how to QUICKLY learn Python
  • Nor do I want to find out the best way to get acquainted with the language
  • Finally, I don't want to know a 'one trick that does it all' approach.

What I do want to know your opinion about, is:

What are the steps YOU would recommend to a Python journeyman, from apprenticeship to guru status (feel free to stop wherever your expertise dictates it), in order that one IMPROVES CONSTANTLY, becoming a better and better Python coder, one step at a time. Some of the people on SO almost seem worthy of worship for their Python prowess, please enlighten us :)

The kind of answers I would enjoy (but feel free to surprise the readership :P ), is formatted more or less like this:

  • Read this (eg: python tutorial), pay attention to that kind of details
  • Code for so manytime/problems/lines of code
  • Then, read this (eg: this or that book), but this time, pay attention to this
  • Tackle a few real-life problems
  • Then, proceed to reading Y.
  • Be sure to grasp these concepts
  • Code for X time
  • Come back to such and such basics or move further to...
  • (you get the point :)

I really care about knowing your opinion on what exactly one should pay attention to, at various stages, in order to progress CONSTANTLY (with due efforts, of course). If you come from a specific field of expertise, discuss the path you see as appropriate in this field.

EDIT: Thanks to your great input, I'm back on the Python improvement track! I really appreciate!

+2  A: 

Google just recently released an online Python class ("class" as in "a course of study").

http://code.google.com/edu/languages/google-python-class/

I know this doesn't answer your full question, but I think it's a great place to start!

dkamins
Thanks @dkamins :) It looks more like a basic tutorial though. Any personal thoughts about a path to continual Python improvement?
Morlock
actually, these video lectures from google are geared more towards itermediate to advanced I think. http://code.google.com/intl/fi-FI/edu/languages/index.html#_python_understanding
Tom Willis
+2  A: 

Not precisely what you're asking for, but I think it's good advice.

Learn another language, doesn't matter too much which. Each language has it's own ideas and conventions that you can learn from. Learn about the differences in the languages and more importantly why they're different. Try a purely functional language like Haskell and see some of the benefits (and challenges) of functions free of side-effects. See how you can apply some of the things you learn from other languages to Python.

Davy8
Haskell is intriguing, and I am drawn to Lisp, but I feel there is much for me still to discover within the Python world before I wish to move on.
Morlock
+26  A: 

One good way to further your Python knowledge is to dig into the source code of the libraries, platforms, and frameworks you use already.

For example if you're building a site on Django, many questions that might stump you can be answered by looking at how Django implements the feature in question.

This way you'll continue to pick up new idioms, coding styles, and Python tricks. (Some will be good and some will be bad.)

And when you see something Pythony that you don't understand in the source, hop over to the #python IRC channel and you'll find plenty of "language lawyers" happy to explain.

An accumulation of these little clarifications over years leads to a much deeper understanding of the language and all of its ins and outs.

dkamins
+1 for "read other people's code, frequently"
FogleBird
@dkamins Thanks for the advices. Sure will dig into specific libraries (for me, that would be Biopython). I wasn't aware of the #python IRC channel. Will also give it a try. :)
Morlock
I would add to this that instead of simply installing a django extension/plugin, try adding the code manually using a git branch. This will force you to actually _read the code_ you are adding to the project.
Noah
+6  A: 

Download Twisted and look at the source code. They employ some pretty advanced techniques.

Jason Christa
Nice. I dug out the twisted code from my python lib folder and will go through it.
Morlock
+2  A: 

I learned python first by myself over a summer just by doing the tutorial on the python site (sadly, I don't seem to be able to find that anymore, so I can't post a link).

Later, python was taught to me in one of my first year courses at university. In the summer that followed, I practiced with PythonChallenge and with problems from Google Code Jam. Solving these problems help from an algorithmic perspective as well as from the perspective of learning what Python can do as well as how to manipulate it to get the fullest out of python.

For similar reasons, I have heard that code golf works as well, but i have never tried it for myself.

inspectorG4dget
You mean this tutorial? Python 2: http://docs.python.org/tutorial/index.html; Python 3: http://docs.python.org/py3k/tutorial/index.html.
Beau Martínez
Thanks for posting the tutorial. I don't know why I haven't been able to find it. I must be selectively blind :O
inspectorG4dget
+13  A: 

Understand Introspection

  • write a dir() equivalent
  • write a type() equivalent
  • figure out how to "monkey-patch"
  • use the dis module to see how various language constructs work

Doing these things will

  • give you some good theoretical knowledge about how python is implemented
  • give you some good practical experience in lower-level programming
  • give you a good intuitive feel for python data structures
Mark Harrison
Nice suggestions. Added to my Python todo list!
Morlock
+4  A: 

Thoroughly Understand All Data Types and Structures

For every type and structure, write a series of demo programs that exercise every aspect of the type or data structure. If you do this, it might be worthwhile to blog notes on each one... it might be useful to lots of people!

Mark Harrison
Wow, I like that idea. This would surely strengthen one's (or my) knowledge of Python's fundamentals.
Morlock
This would not only be useful in Python, but also as in an abstract sense.
Beau Martínez
+2  A: 

Have you seen the book "Bioinformatics Programming using Python"? Looks like you're an exact member of its focus group.

Tim Pietzcker
Thanks for the reference. I'll make my University library buy this one :)
Morlock
Reading it right now. Learning a few things!
Morlock
+14  A: 

Understand (more deeply) Python's data types and their roles with regards to memory mgmt

As some of you in the community are aware, I teach Python courses, the most popular ones being the comprehensive Intro+Intermediate course as well as an "advanced" course which introduces a variety of areas of application development.

Quite often, I get asked a question quite similar to, "Should I take your intro or advanced course? I've already been programming Python for 1-2 years, and I think the intro one is too simple for me so I'd like to jump straight to the advanced... which course would you recommend?"

To answer their question, I probe to see how strong they are in this area -- not that it's really the best way to measure whether they're ready for any advanced course, but to see how well their basic knowledge is of Python's objects and memory model, which is a cause of many Python bugs written by those who are not only beginners but those who have gone beyond that.

To do this, I point them at this simple 2-part quiz question: Ex1: x=42; y=x; x+=1; print x,y Ex2: x=[1,2,3];y=x;x[0]=4;print x,y

Many times, they are able to get the output, but the why is more difficult and much more important of an response... I would weigh the output as 20% of the answer while the "why" gets 80% credit. If they can't get the why, regardless how Python experience they have, I will always steer people to the comprehensive intro+intermediate course because I spend one lecture on objects and memory management to the point where you should be able to answer with the output and the why with sufficient confidence. (Just because you know Python's syntax after 1-2 years doesn't make you ready to move beyond a "beginner" label until you have a much better understanding as far as how Python works under the covers.)

A succeeding inquiry requiring a similar answer is even tougher, e.g.,

Example 3

x = ['foo', [1,2,3], 10.4]
y = list(x) # or x[:]
y[0] = 'fooooooo'
y[1][0] = 4
print x
print y

The next topics I recommend are to understanding reference counting well, learning what "interning" means (but not necessarily using it), learning about shallow and deep copies (as in Example 3 above), and finally, the interrelationships between the various types and constructs in the language, i.e. lists vs. tuples, dicts vs. sets, list comprehensions vs. generator expressions, iterators vs. generators, etc.; however all those other suggestions are another post for another time. Hope this helps in the meantime! :-)

ps. I agree with the other responses for getting more intimate with introspection as well as studying other projects' source code and add a strong "+1" to both suggestions!

pps. Great question BTW. I wish I was smart enough in the beginning to have asked something like this, but that was a long time ago, and now I'm trying to help others with my many years of full-time Python programming!!

wescpy
Wesley Chun! Morlock, this is the kind of guy you were talking about in the bolded part of your question. A deeply knowledgable guy who also a very gifted teacher, I got a huge boost from the book.
bvmou
thx @bvmou! i could only answer this question because i had to go through this learning process like everyone else... only mine was 13 years ago! :-) thx for plugging http://corepython.com tho! :-)
wescpy
A: 

Go back on a regular basis to the Python challenge. You'll get better.

e-satis
Python challenge is too cryptic for its own good.
Beau Martínez
I tried the Python challenge a year ago or more and found it was not an efficient way of using my learning time. I progressed much more rapidly when I decided to read a few recognized Python book or re-reading them (official Python tutorial, Learning Python from O'Reilly...)
Morlock
@Morlock Dive Into Python is *the* book I recommend. Python 2: http://diveintopython.org/; Python 3: http://diveintopython3.org/.
Beau Martínez
@Beau Martínez My first impression of this book was that it was less interesting to start with then Learning Python, which I am extremely happy to have chose as my second Python book. Now looking at the table of content of Dive in Python, and given your strong support, I'll give it a thorough try. After all, this only brings my Python reading list to 3000+ pages :) But I'll manage to do that before Christmas, hopefully. Thanks for all your great input on this question!
Morlock
+12  A: 

Check out Peter Norvig's essay on becoming a master programmer in 10 years: http://norvig.com/21-days.html. I'd wager it holds true for any language.

twneale
Right, I had come across this one some time ago, but didn't read through. Thx!
Morlock
+8  A: 

I'll give you the simplest and most effective piece of advice I think anybody could give you: code.

You can only be better at using a language (which implies understanding it) by coding. You have to actively enjoy coding, be inspired, ask questions, and find answers by yourself.

Got a an hour to spare? Write code that will reverse a string, and find out the most optimum solution. A free evening? Why not try some web-scraping. Read other peoples code. See how they do things. Ask yourself what you would do.

When I'm bored at my computer, I open my IDE and code-storm. I jot down ideas that sound interesting, and challenging. An URL shortener? Sure, I can do that. Oh, I learnt how to convert numbers from one base to another as a side effect!

This is valid whatever your skill level. You never stop learning. By actively coding in your spare time you will, with little additional effort, come to understand the language, and ultimately, become a guru. You will build up knowledge and reusable code and memorise idioms.

Beau Martínez
Now, that is inspiring! Thanks for your input.
Morlock
+46  A: 

I thought the process of Python mastery went something like:

  1. Discover list comprehensions
  2. Discover generators
  3. Incorporate map, reduce, filter, iter, range, xrange often into your code
  4. Discover Decorators
  5. Write recursive functions, a lot
  6. Discover itertools and functools
  7. Read Real World Haskell
  8. Rewrite all your old Python code with tons of higher order functions, recursion, and whatnot.
  9. Annoy your cubicle mates every time they present you with a Python class. Claim it could be "better" implemented as a dictionary plus some functions. Embrace functional programming.
  10. Rediscover the Strategy pattern and then all those things from imperative code you tried so hard to forget after Haskell.
  11. Find a balance.
wheaties
+1 for giving more reasons to head over to Real World Haskell.
jeffjose
@wheaties Super nice list, love it! You seem to have a bias towards functional programing and away from object oriented... is there a particular reason? Has the Haskell experience rerouted you towards this approach?
Morlock
Yes and no. I find I write better and more concise code the closer I get to functional programming. That said, there are plenty of places where things are expressed more clearly in an imperative manner. There's a reason Real World Haskell is sold out at Python conventions, it makes you a better programmer. My advice, explore as many facets of Python as you can, then try a functional language.
wheaties
@wheaties gets the reply since it is both the closer to the format asked for and very inspiring. Thanks for taking your time to reply!
Morlock
@wheatis I'm now scared if I read into Haskell I'll abandon Python for good.
Beau Martínez
+1, best answer here. :)
missingfaktor
Beginners: Dictionarythen later on...Mastery: Metaprogramming
gath
You better learn range/xrange before you learn listcomps...
djc
Could you elaborate on >>it could be "better" implemented as a dictionary plus some functions.<< ?
Koobz
@Koobz I'm trying to put into words exactly what I meant by that statement which after rereading this long time almost appears as if I'm promoting procedural programming. That is not the case. The comment stems from the way a Python class is organized and what hidden dangers lurk via the "__dict__" property. I really can't expand more in the small space of this comment.
wheaties
Can i heartily recommend [Dive Into Python](http://diveintopython.org/) as a way of doing #1, 2, 3, and 4? That book helped me tons
Claudiu
+1  A: 

You already have a lot of reading material, but if you can handle more, I recommend you learn about the evolution of python by reading the Python Enhancement Proposals, especially the "Finished" PEPs and the "Deferred, Abandoned, Withdrawn, and Rejected" PEPs.

By seeing how the language has changed, the decisions that were made and their rationales, you will absorb the philosophy of Python and understand how "idiomatic Python" comes about.

http://www.python.org/dev/peps/

Greg Ball