Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elegant Python? [closed]

Tags:

python

I am trying to teach myself Python, and I have realized that the only way I really learn stuff is by reading the actual programs. Tutorials/manuals just cause me to feel deeply confused.

It's just my learning style, and I'm like that with everything I've studied (including natural languages -- I've managed to teach myself three of them by just getting into the actual 'flow of it').

Classical music once had the concept of a 'gamut' -- playing the entire range of an instrument in an artful manner. I'm guessing that there may be a few well-written scripts out there that really show off every feature of the language. It doesn't matter what they do, I just want to start studying Python by reading programs themselves.

I remember coming across a similar method years ago when I studied some LISP. It was a book, published by Springer Verlag, consisting solely of AI programs, to be read for their didactic merit.

like image 243
magnetar Avatar asked Aug 06 '10 22:08

magnetar


1 Answers

I would recommend studying the Standard Python Library (all the parts of it that are coded in Python, that is) -- it's not uniformly excellent in elegance, but it sets a pretty high standard. Plus, the study has the extra benefit of making you very familiar with the library itself (an absolutely crucial part of mastering Python), in addition to showing you a lot good to excellent Python style code;-).

Edit: I have to point out (or my wife and co-author Anna has threatened to not cook the yummy steak I see waiting;-) that the Python Cookbook, 2nd printed edition, also has a lot of code examples, in the best style Anna and I could make them, and with substantial discussion of style variations and alternatives. However, it's stuck back in time to the days of Python 2.4 (sorry, no time to do a third edition for now...), and that's a real block for some people (though I think that having learned good Python 2.4 style, moving to good 2.7 or 3.1 style is really an "incremental" matter, that's definitely a subjective opinion). "Declaring my interest": Anna and I still get some royalties if you buy the book, and, more importantly, the Python Software Foundation (near and dear to both our hearts -- our Prius's vanity license plate reads "P♥THON"...!-) gets more -- so obviously we're biased in the book's favor;-). If you don't want to spend money, you can read some parts of the book online and for free on Google Books (O'Reilly gets to pick and choose which parts are thus freely readable, so please don't complain to me [[or Anna]] about those choices...!-).

I wish I could recommend the online edition of the Cookbook, which does have recipes that are very recent as well as the classic old ones among which we picked and chose most of the printed edition's ones -- but, unfortunately, there are lots of style issues with too many of the online recipes to recommend them collectively as "good style examples" (and that goes for the good recipes too: most of the recipes we picked for the book, we also heavily edited to improve style (and readability, and performance, but those often go hand-in-hand with Python).

like image 112
Alex Martelli Avatar answered Oct 11 '22 17:10

Alex Martelli