The Evolution of a Python Programmer is funny, but it only covers one aspect of programming. Many times I will see code that is fine from a CS point of view, but absolutely horrible when it comes to program structure and module organization.
You often see people saying things like "Hello World in python is just 'print "Hello World"'", and that is true. It is very easy to get started writing python, but if you don't structure your modules correctly, you will be in a world of pain later on. It is something that can be hard to explain, since the results in the short term are the same, and it may not be clear at first why one way of doing things is better than the other.
Instead of Hello World, let's take the example of a program to get stock quotes. The actual implementation here is not relevant, pretend it contacts a web service or database or something.
A common case is the "python script". I HATE python scripts. "script" almost always ends up being a single file with no entry points, no main function, and mixes IO with logic.
s = raw_input("symbol:")
if s == 'MSFT':
print 'price=', 28.23
elif s == 'GOOG':
print 'price=', 546.43
The first step in fixing this is to define an actual function. Now you can import the module and run get_price().
def get_price(): s = raw_input("symbol:") if s == 'MSFT': print 'price=', 28.23 elif s == 'GOOG': print 'price=', 546.43
The (hopefully) obvious problem with this is that the IO is mixed in with the logic. What if you wanted to get the stock price for 1000 stocks and output a nice summary? This next version is slightly better, here the input is a proper parameter, but you still have no control over the output. You could get your 1000 quotes, but you would have no way to report on the output. Again, this should be obvious, but I come across code that does this way too often.
def get_price(s): if s == 'MSFT': print 'price=', 28.23 elif s == 'GOOG': print 'price=', 546.43 ### if __name__ == "__main__": s = raw_input("symbol:") get_price(s)
The first respectable version adds a main() function that
handles the input and output. The main function should also get the
stock from the command line arguments, rather than interactively. I
think you tend to see things like this more often from windows
users, who like to double click on things rather than run them from
a shell. You could probably write a whole book on this subject
though 
def get_price(s): if s == 'MSFT': return 28.23 elif s == 'GOOG': return 546.43 ### def main(): s = raw_input("symbol:") print 'price=', get_price(s) if __name__ == "__main__": main()
The final steps are to make a proper python package out of this module, but I'll save that for a later post.