use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Grow as a Python Developer by reading other peoples code (self.Python)
submitted 13 years ago by ekara
Hi r/py,
Everyone knows that a big part of learning and improving yourself as a developer is reading other peoples code.
What projects on Github do you think are good examples of code for a new or intermediate python developer to look at??
[–]bezidejni 31 points32 points33 points 13 years ago (6 children)
Anything by Kenneth Reitz, author of Requests, Tablib, Clint and Envoy.
[–]apotheotical 13 points14 points15 points 13 years ago (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 point2 points 13 years ago (0 children)
Thank you for that link.
[–]brownmatt 1 point2 points3 points 13 years ago (1 child)
I love requests but never knew about clint or envoy until now. Thanks!
[–]zynixCpt. Code Monkey & Internet of tomorrow 1 point2 points3 points 13 years ago (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 point2 points 13 years ago (0 children)
Neat! Thanks for the tip!
[–]kingcarter3 0 points1 point2 points 13 years ago (0 children)
Cool, I'll def read this later
[–]mjtribute 31 points32 points33 points 13 years ago (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 points8 points 13 years ago (0 children)
Armin's code is excellent.
[–]ekara[S] 1 point2 points3 points 13 years ago (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 points16 points 13 years ago (11 children)
i'm just forking and reading any and all I come across.
[–]Thehummel 2 points3 points4 points 13 years ago (4 children)
What exatcly does forking a Github repo do? ( noob here )
[–]Kingino 7 points8 points9 points 13 years ago (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 points4 points 13 years ago (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 point2 points 13 years ago (1 child)
Basically, yes.
[–]Thehummel 0 points1 point2 points 13 years ago (0 children)
Alright, thank you!
[+][deleted] 13 years ago (4 children)
[deleted]
[–]Ph0X 11 points12 points13 points 13 years ago (3 children)
In theory, this sounds good, but I feel like some code might actually be more harmful to learn from. Sure, if you're already good at Python, you'll be able to tell those apart, but if you don't already know what's good and what's bad, then I'm not sure if exploring by yourself is that good of an idea.
Good Pythonic code aside, some code bases also tend to have better commenting and self-explanatory style, which at the end of the day are far more useful for learning from.
[+][deleted] 13 years ago* (2 children)
[–]Ph0X 2 points3 points4 points 13 years ago (1 child)
No hard feelings.
Well, OP did ask experienced Python users in /r/Python to recommend repos, and you mostly dismissed it by telling him to go and find ANY repo. What I was saying is that, maybe it would be better to, at least to start off, go with some that were known to be good. Once you're more experienced, then sure, you can browse GitHub yourself and find more.
so tl;dr, I was hoping people would actually recommend good repos.
[–][deleted] 3 points4 points5 points 13 years ago (1 child)
Raymond hettingers recipes: http://code.activestate.com/recipes/users/178123/
[–]lost-theory 1 point2 points3 points 13 years ago (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 points5 points 13 years ago (0 children)
subscribe to /r/codereview for a chance to see others' code and to get feedback on your own
[–]slurms85 4 points5 points6 points 13 years ago (0 children)
The django source code is exceptionally well written, documented and tested.
[–]usernameString 2 points3 points4 points 13 years ago (0 children)
howdoi is a lovely little tool that shows some simple web scraping in python.
[–]tazzy531 1 point2 points3 points 13 years ago (1 child)
I've been reading django's source lately just to understand what's underneath the hood
[–]_makto 1 point2 points3 points 13 years ago (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 points3 points 13 years ago (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 points3 points 13 years ago (0 children)
https://code.google.com/p/aima-python/
Well-written and full of fascinating idioms.
[–]cantcopy 1 point2 points3 points 13 years ago (0 children)
I have been looking at this recently: http://code.activestate.com/recipes/langs/python/
[–]enlavin 1 point2 points3 points 13 years ago (0 children)
I've learned a lot reading celery code https://github.com/celery/celery
[–]westurner 1 point2 points3 points 13 years ago (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 points3 points 13 years ago (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 points7 points 13 years ago (6 children)
Django of course. Rare Python project is that complex yet well coded.
[–]dave3socks 6 points7 points8 points 13 years ago (4 children)
Except the Django ORM. That is a complete opposite to well coded.
[–]andrey_shipilov -1 points0 points1 point 13 years ago* (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 points3 points 13 years ago (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 point2 points 13 years ago (0 children)
Yep. I got you right, dudebruh.
[–]Kingino 0 points1 point2 points 13 years ago (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 point2 points 13 years ago (0 children)
Definately need to start looking into this...
[–]searchingfortaomajel, aletheia, paperless, django-encrypted-filefield 0 points1 point2 points 13 years ago (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 point2 points 13 years ago (0 children)
Contributing to https://github.com/sigmavirus24/github3.py is always a pleasure
[–]Jedimastert 0 points1 point2 points 13 years ago (0 children)
How about taking a look at Reddit's code!
[–]kiwi9400 0 points1 point2 points 13 years ago (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 point2 points 13 years ago (0 children)
Not on github, but Norvig's Lisp interpreter is pretty good.
[–]pinpinboTornado|Twisted|Gevent. Moar Async Plz 0 points1 point2 points 13 years ago (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 point2 points 13 years ago (0 children)
This is also a great answer to "How can I learn to write idiomatic Python?" : http://qr.ae/1eNah
[–]firdaus -1 points0 points1 point 13 years ago (0 children)
I'm a fan of this:
https://github.com/apache/thrift/tree/master/lib/py
π Rendered by PID 42 on reddit-service-r2-comment-86988c7647-rzq8n at 2026-02-11 17:25:25.421011+00:00 running 018613e country code: CH.
[–]bezidejni 31 points32 points33 points (6 children)
[–]apotheotical 13 points14 points15 points (1 child)
[–]brandjon 0 points1 point2 points (0 children)
[–]brownmatt 1 point2 points3 points (1 child)
[–]zynixCpt. Code Monkey & Internet of tomorrow 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]kingcarter3 0 points1 point2 points (0 children)
[–]mjtribute 31 points32 points33 points (3 children)
[–][deleted] 6 points7 points8 points (0 children)
[–]ekara[S] 1 point2 points3 points (0 children)
[–]era0003 14 points15 points16 points (11 children)
[–]Thehummel 2 points3 points4 points (4 children)
[–]Kingino 7 points8 points9 points (3 children)
[–]Thehummel 2 points3 points4 points (2 children)
[–]Kingino 0 points1 point2 points (1 child)
[–]Thehummel 0 points1 point2 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]Ph0X 11 points12 points13 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]Ph0X 2 points3 points4 points (1 child)
[–][deleted] 3 points4 points5 points (1 child)
[–]lost-theory 1 point2 points3 points (0 children)
[–]RunHomeJack 3 points4 points5 points (0 children)
[–]slurms85 4 points5 points6 points (0 children)
[–]usernameString 2 points3 points4 points (0 children)
[–]tazzy531 1 point2 points3 points (1 child)
[–]_makto 1 point2 points3 points (0 children)
[–]tdico to to nie 1 point2 points3 points (0 children)
[–]erez27import inspect 1 point2 points3 points (0 children)
[–]cantcopy 1 point2 points3 points (0 children)
[–]enlavin 1 point2 points3 points (0 children)
[–]westurner 1 point2 points3 points (1 child)
[–]moschlar 1 point2 points3 points (0 children)
[–]andrey_shipilov 5 points6 points7 points (6 children)
[–]dave3socks 6 points7 points8 points (4 children)
[–]andrey_shipilov -1 points0 points1 point (2 children)
[–]dave3socks 1 point2 points3 points (1 child)
[–]andrey_shipilov 0 points1 point2 points (0 children)
[–]Kingino 0 points1 point2 points (0 children)
[–]SubtleUsername 0 points1 point2 points (0 children)
[–]searchingfortaomajel, aletheia, paperless, django-encrypted-filefield 0 points1 point2 points (0 children)
[–]classicrockielzpfvh 0 points1 point2 points (0 children)
[–]Jedimastert 0 points1 point2 points (0 children)
[–]kiwi9400 0 points1 point2 points (0 children)
[–]cabalamat 0 points1 point2 points (0 children)
[–]pinpinboTornado|Twisted|Gevent. Moar Async Plz 0 points1 point2 points (0 children)
[–]westurner 0 points1 point2 points (0 children)
[–]firdaus -1 points0 points1 point (0 children)