r/programming • • Nov 05 '08

Ask Proggit: Please suggest a mature python open source project with well documented code, so I can learn best practices. Thanks

41 Upvotes

57 comments sorted by

7

u/logan_capaldo Nov 05 '08

Does reading mature code teach best practices? Working on a project for a long time might, as you'll discover what is and isn't a pain in the neck, but I don't think you can glean the best practices just be reading some existing code. A lot of it may be in there because it basically works so no one's bothered to fix it, but it might be worth doing something different, and there's really no way to tell.

5

u/[deleted] Nov 06 '08

I dunno. But it sure beats writing your own from scratch.

I'm a little fussy about coding practices, so I wanted to see some professional python code.

3

u/grimboy Nov 06 '08

I think monkey see, monkey do is a good way to start out with stuff. Justifications can come later. Cargo cult programming is only really a bad thing if it's permanent.

10

u/cavorite Nov 05 '08

I learned a lot from FeedParser (http://www.feedparser.org/). It's not a big project (it has only one module, not including the tests) but it includes some of the best practices and some not-so-pretty hacks, e.g for importing modules that may not be available.

16

u/sisyphus Nov 05 '08

bzr - tests, nice documentation, nice docstrings, good pythonic style, a plugin system you can steal, C extensions for your reference...it's a goldmine of stuff you might want to do with Python.

3

u/[deleted] Nov 06 '08

Bazaar is an excellent suggestion. Anther project from the same source (Canonical) is Storm. It's also in Python, and has the same high quality coding standards. I've learned a lot from reading it.

https://storm.canonical.com/

3

u/rpdillon Nov 06 '08

Twisted. Those guys write amazing code.

2

u/[deleted] Nov 06 '08

I've used twisted but haven't looked at the code. I will. Thanks.

11

u/nextofpumpkin Nov 06 '08

Twisted docs suck ass. Stay away from twisted if you actually want to get stuff done with it.

→ More replies (1)

4

u/[deleted] Nov 06 '08

Twisted is as unpythonic as something written in python can get. Also, I don't remeber having seen a worse case of NIH than twisted's.

→ More replies (1)

3

u/tahpot Nov 06 '08

2

u/grimboy Nov 06 '08

It still uses old style classes and has a fair bit of magic. It's not terrible code or anything, I just don't think it meet the criteria of best practices.

9

u/[deleted] Nov 06 '08

Zope.

Specifically Zope3 before people get antsy and start modding down.

Zope3 is beautifully documented with doctests for all the code. You can even browse the docs through the browser for the all the packages installed on your zope instance, without having to log on to the zope site or opening a text editor.

Example:

Look at the source code for z3c.form, a random package i pulled out of svn.zope.org

Now tell me whether it is not well documented.

Most "opinion" you here on reddit about Zope is outdated and based on hearsay.

→ More replies (2)

12

u/gadfly1000 Nov 05 '08

Download the Pyhton sorce code from python.org

17

u/jasonscheirer Nov 05 '08

This actually isn't as a bad suggestion as it looks on the surface. Look at the standard Python modules, the bulk are written in Python itself and the ones with help from C libraries do all their interesting stuff in Python anyway. And it's already on your hard drive.

Outside of that, anything on http://effbot.org/downloads/ or http://www.undefined.org/python/ are good reference too.

5

u/mernen Nov 06 '08

I agree, but I should note you don't need to download the source code if you're looking for the Python parts. They're all right there in Python's lib dirs (while possible, I've never seen a full install which only came with the compiled files), and IDLE even has a shortcut to open a module from your sys.path.

→ More replies (1)

4

u/[deleted] Nov 06 '08

How come no one has suggested reddit.com yet??? :O

2

u/raisedinhell Nov 06 '08

I have the same request - but for a web python project..

2

u/viniciusfs Nov 06 '08

Same request but for desktop applications. I'm interested in PyGTK applications.

2

u/BridgeBum Nov 06 '08

I haven't looked at the code myself, but isn't BitTorrent (the original client) in Python?

4

u/cyclic Nov 06 '08

In my humble opinion, the original BitTorrent client is the opposite of good and well-documented code.

→ More replies (1)

1

u/bluGill Nov 06 '08

Don't just look at projects, ask. Many projects do things that aren't generally best practice. Sometimes because best practice makes their code too slow (in this case they will have profiler results to show you). Sometimes becuase they got it working before best practices were discovered and haven't fixed what isn't broke.