Live data from Hacker News

Ask HN: Good python code for code reading

news.ycombinator.com

1–10 of 23 posts

Re: Ask HN: Good python code for code reading

#2
I would definitely recommend sync'ing the python subversion tree and picking a few modules and reading through them. Doing so taught me some of the less obvious things within the language, and also taught me a lot about the various dunder (__foo__) methods for objects.

Additionally, I'd recommend reading through the PEP documents (http://python.org/dev/peps/) - there's a lot of great examples and rationales contained in those.

Finally, Doug hellmann has done an excellent job with his Python Module of the Week series (http://www.doughellmann.com/PyMOTW/) and a new project "The hazel tree" (http://www.thehazeltree.org/) is doing a great job at compiling the various examples, docs/etc together in one place.

Re: Ask HN: Good python code for code reading

#5
For performance and algorithms the implementations at http://shootout.alioth.debian.org/u32q/python.php and pay attention to the different benchmarks.

Also all RPython code coming from pypy, sometimes shown in http://morepypy.blogspot.com/

They are reimplementing all the C modules and doing a great job. The new implementations are of course closer to current best practices in python.

Enjoy.

Re: Ask HN: Good python code for code reading

#6
post #3

BitTorrent http://download.bittorrent.com/dl/

http://www.onlamp.com/pub/a/python/2003/7/17/pythonnews.html

This article might help you along the way. Inside it is a link to Bram Cohen's blog post titled "How to Write Maintainable Code". I have never actually looked into the Bittorrent code myself but depending on your skill level, understanding whats going on in there might be a bumpy ride.

Re: Ask HN: Good python code for code reading

#8
post #2

I would definitely recommend sync'ing the python subversion tree and picking a few modules and reading through them. Doing so taught me some of the less obvious things within the language, and also taught me a lot about the various dunder (__foo__) methods for objects. Additionally, I'd recommend reading through the PEP documents ( http://python.org/dev/peps/ ) - there's a lot of great examples and rationales contain…

This was a major eye-opener for me as-well. I jumped into various python modules and was amazed at what I discovered. Like the easter-egg hidden away in "this.py":

http://pastebin.com/f25f08f20

(Couldn't figure out how to get code formatting to work properly)

Re: Ask HN: Good python code for code reading

#9
post #8
post #2

I would definitely recommend sync'ing the python subversion tree and picking a few modules and reading through them. Doing so taught me some of the less obvious things within the language, and also taught me a lot about the various dunder (__foo__) methods for objects. Additionally, I'd recommend reading through the PEP documents ( http://python.org/dev/peps/ ) - there's a lot of great examples and rationales contain…

This was a major eye-opener for me as-well. I jumped into various python modules and was amazed at what I discovered. Like the easter-egg hidden away in "this.py": http://pastebin.com/f25f08f20 (Couldn't figure out how to get code formatting to work properly)

Ha. All that code at the bottom of the file could be replaced by "print s.decode('rot13')" - I suppose it's backwards compatible though...
Post reply on HN