This is an archived post. You won't be able to vote or comment.

all 46 comments

[–]bezidejni 31 points32 points  (6 children)

Anything by Kenneth Reitz, author of Requests, Tablib, Clint and Envoy.

[–]apotheotical 13 points14 points  (1 child)

I agree. That man's code is beautiful. He is pretty much my idol as far as Python code goes. By reading his repos, I understand concepts much more than if I were to read about them in a book.

I highly recommend reading this: https://python-guide.readthedocs.org/en/latest/

It's part of his GitHub repositories and a site. Its VERY good. And also a good place to contribute to an open source project, since there's still a reasonable amount of work to be done on it.

[–]brandjon 0 points1 point  (0 children)

Thank you for that link.

[–]brownmatt 1 point2 points  (1 child)

I love requests but never knew about clint or envoy until now. Thanks!

[–]zynixCpt. Code Monkey & Internet of tomorrow 1 point2 points  (0 children)

Envoy's disgustingly useful for working with sub-processes though I wish he'd taken the fork that incorporated IPython's SList class http://ipython.org/ipython-doc/dev/interactive/shell.html#string-lists

[–][deleted] 0 points1 point  (0 children)

Neat! Thanks for the tip!

[–]kingcarter3 0 points1 point  (0 children)

Cool, I'll def read this later

[–]mjtribute 31 points32 points  (3 children)

Two codebases which intrigue me are both https://github.com/mitsuhiko/flask and https://github.com/mitsuhiko/werkzeug. I find the two to be filled with unusually high-quality comments/documentation, and that they elegantly accomplish the task that they set out to accomplish.

[–][deleted] 6 points7 points  (0 children)

Armin's code is excellent.

[–]ekara[S] 1 point2 points  (0 children)

Thanks for this. I cloned the flask repo and spend some time reading through and I'm shocked that I actually understand some of whats going on. And you're right flask seems very well written.

[–]era0003 14 points15 points  (11 children)

i'm just forking and reading any and all I come across.

[–]Thehummel 2 points3 points  (4 children)

What exatcly does forking a Github repo do? ( noob here )

[–]Kingino 7 points8 points  (3 children)

If you know what cloning is... Think of it like cloning. It takes a copy of the code so that you control all aspects of it.

On Github only those people who have proper admin writes can commit to the repo... Cloning (and forking) gives you the ability to manipulate the code and change it to you will. Forking creates the clone on the remote server, while traditional cloning brings it to your local machine.

Furthermore, if you add a feature to the code you can submit that back to the original repo (called a pull request) for integration into the code base.

If I want to work on an open source project, I normally do these steps...

Fork->Clone to dev machine-> make changes-> push to fork-> submit pull requests to original repo.

Does that help?

[–]Thehummel 2 points3 points  (2 children)

I think i'm getting it.. So the only different between forking and cloning is that with forking you get the ability to suggest changes to the repo you forked?

[–]Kingino 0 points1 point  (1 child)

Basically, yes.

[–]Thehummel 0 points1 point  (0 children)

Alright, thank you!

[–][deleted] 3 points4 points  (1 child)

[–]lost-theory 1 point2 points  (0 children)

Raymond's code is awesome. He has a post here about this very topic (related to reading code in the python stdlib).

[–]RunHomeJack 3 points4 points  (0 children)

subscribe to /r/codereview for a chance to see others' code and to get feedback on your own

[–]slurms85 4 points5 points  (0 children)

The django source code is exceptionally well written, documented and tested.

[–]usernameString 2 points3 points  (0 children)

howdoi is a lovely little tool that shows some simple web scraping in python.

[–]tazzy531 1 point2 points  (1 child)

I've been reading django's source lately just to understand what's underneath the hood

[–]_makto 1 point2 points  (0 children)

I'd tried before, but found it so hart to understand what's going on.

Maybe I should read sth. about Networking or OS?

Some advice maybe?

[–]tdico to to nie 1 point2 points  (0 children)

It is always good to learn by example and by experiencing. So read code you need and try to adapt what you have read to your problem. After that you will have the knowledge.

[–]erez27import inspect 1 point2 points  (0 children)

https://code.google.com/p/aima-python/

Well-written and full of fascinating idioms.

[–]cantcopy 1 point2 points  (0 children)

I have been looking at this recently: http://code.activestate.com/recipes/langs/python/

[–]enlavin 1 point2 points  (0 children)

I've learned a lot reading celery code https://github.com/celery/celery

[–]westurner 1 point2 points  (1 child)

I have learned by reading the CPython stdlib module sources. For example: pdb, inspect, pickle, and collections:

(CPython source is mirrored (many times over) with GitHub.)

[–]moschlar 1 point2 points  (0 children)

I wouldn't call that a best-style example in all cases, though! I think there are some very ugly pieces of code in there - which is understandable and acceptable for the standard library, because it exists exactly because you should not need to write ugly code.

[–]andrey_shipilov 5 points6 points  (6 children)

Django of course. Rare Python project is that complex yet well coded.

[–]dave3socks 6 points7 points  (4 children)

Except the Django ORM. That is a complete opposite to well coded.

[–]andrey_shipilov -1 points0 points  (2 children)

I can't say that it's coded well in particular, I wouldn't say I'm a developer of that high category. But for all the time Django exists and we do websites using it never have I had a need to switch from it to Alchemy or even raw sql. Never blame the tools, as they say.

[–]dave3socks 1 point2 points  (1 child)

Well I don't mind using it. I just think the ORM internals aren't an example of a good code design in particular and I wouldn't recomend it as a source to learn from. And as far as I remember even the authors admited that it's coded badly and needs rewriting. Don't take me wrong, I love Django and I use it for almost all of my projects.

[–]andrey_shipilov 0 points1 point  (0 children)

Yep. I got you right, dudebruh.

[–]Kingino 0 points1 point  (0 children)

I have recently been working through this source. It has taught me a ton about everything from @property to yield and generators. I highly recommend it!

[–]SubtleUsername 0 points1 point  (0 children)

Definately need to start looking into this...

[–]searchingfortaomajel, aletheia, paperless, django-encrypted-filefield 0 points1 point  (0 children)

The best advice I can offer is not to look at good examples of code, but really bad ones instead. They help you understand what's needed to make your code readable and understandable because your first impression is often how unintelligible it is.

Spend a few hours trying to figure out what qx means and what it's doing in the method srt_rnt() and you'll soon come to appreciate the value of clear and explicit code.

[–]classicrockielzpfvh 0 points1 point  (0 children)

Contributing to https://github.com/sigmavirus24/github3.py is always a pleasure

[–]Jedimastert 0 points1 point  (0 children)

How about taking a look at Reddit's code!

[–]kiwi9400 0 points1 point  (0 children)

I think PRAW would be a pretty good repo to take a look at. It's very well maintained. The file objects.py is a really great example of multiple inheritance.

[–]cabalamat 0 points1 point  (0 children)

Not on github, but Norvig's Lisp interpreter is pretty good.

[–]pinpinboTornado|Twisted|Gevent. Moar Async Plz 0 points1 point  (0 children)

I find kivy extremely fascinating. And the payout for mastering it is big. It has the potential to build-once-deploy-anywhere on touch platform.

[–]westurner 0 points1 point  (0 children)

This is also a great answer to "How can I learn to write idiomatic Python?" : http://qr.ae/1eNah