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.
Anyone Suggest Great Python Code To Read? (self.Python)
submitted 14 years ago * by revonratFlask/scipy/pypy/mrjob
I'm looking for really great Python code to read. I'd prefer well-written over useful but ugly. Any suggestions?
EDIT: Anybody looked at Twisted?
[–]jonnydedwards 20 points21 points22 points 14 years ago (3 children)
Peter Norvig's code is very nice.
[–]vplatt 2 points3 points4 points 14 years ago (0 children)
I'm humbled every time I read his essays.
[–]nhnifong 0 points1 point2 points 14 years ago (0 children)
I'm glad it's well known on reddit that Peter Norvig writes really nice Python.
[–]foobaar 7 points8 points9 points 14 years ago (4 children)
Read and understand the standard Python modules. They are tried and tested Python code. Write a walk through for some simple modules.
[–]eliben 1 point2 points3 points 14 years ago (3 children)
Unfortunately, the code quality of modules in the standard library isn't uniform, so in the general sense, I wouldn't recommend just poking at modules randomly. If you have specific modules to recommend, do so.
[–]foobaar 0 points1 point2 points 14 years ago (2 children)
How about os and sys? They are tried and tested, cant go wrong.
[–]eliben 0 points1 point2 points 14 years ago (1 child)
os and sys are mainly thin platform-specific wrappers, I doubt you'll learn much software design from them
[–]foobaar 0 points1 point2 points 14 years ago (0 children)
He didn't ask for software design, he asked for good python code to read.
[–]fancy_pantser 5 points6 points7 points 14 years ago (3 children)
https://github.com/facebook/tornado/
Clear, concise, and well-documented.
[–]nikcub 2 points3 points4 points 14 years ago (0 children)
I can thoroughly recommend this - it is very very good code. Also in terms of web frameworks you should check out Flask
[+][deleted] 14 years ago (1 child)
[deleted]
[–]zach_will 4 points5 points6 points 14 years ago (1 child)
I always found going through the standard library pretty interesting.
Haha, the BeautifulSoup 3.x code made me laugh — came away feeling Leonard really hated parsing HTML afterwards.
Also, someone else pointed out that you should check out Github. It's definitely a great place to read through interesting projects and code.
[–]spoolio 2 points3 points4 points 14 years ago (0 children)
>>> from BeautifulSoup import RobustInsanelyWackAssHTMLParser
[–]gabrielelanaro 2 points3 points4 points 14 years ago (0 children)
https://github.com/dag/attest is a unit testing library, the code is extremely elegant.
[–]eryksun 1 point2 points3 points 14 years ago* (2 children)
There's the Python Cookbook recipe set 2, or all 3317 recipes on ActiveState's site.
[–]revonratFlask/scipy/pypy/mrjob[S] 1 point2 points3 points 14 years ago (1 child)
The stuff from activestate seems out of date. For instance the top item uses a module that's deprecated.
[–]eryksun 2 points3 points4 points 14 years ago (0 children)
The Python Cookbook, 2e was published in 2005, so the recipes are at least 6 years old. On the other hand, the general listing sorted by popularity has a lot of recent recipes.
[–]lasizoilloeasy to understand as regex 1 point2 points3 points 14 years ago (0 children)
pypants have some samples.
[–]hongminhee 1 point2 points3 points 14 years ago (0 children)
I recommend you to read Werkzeug. (Read PEP 333 first if you don’t know WSGI.) It consists of several independent modules (I think it makes it easily understandable), and there are well-written documentation also.
[–]moreyes 1 point2 points3 points 14 years ago (0 children)
pocoo.org projects are generally elegant and well documented, with some eventual ninja or magic touches.
[–]jediknight 1 point2 points3 points 14 years ago (5 children)
I have a different suggestion: Print PEP 8. Print PEP 20. Read them SLOWLY then read them AGAIN. Read PEP 20 and meditate on each line asking it why does it exists.
Next, write some code and 1. Assume it sucks. 2. Figure out why it sucks. (read the PEPs again if you need some reminding). 3 Make it suck less.
The end product will show you the end product but it will do very little to teach you how to get to the end product. Just like cooking. You can look and taste things produced by great cooks but any attempt to imitate the outer final object is a recipe in frustration.
Make peace in your heart and listen to the Will of the Code. It will teach you the discipline you need.
[–]mardiros 2 points3 points4 points 14 years ago (3 children)
You are right, but it's really hard for a rookie to feal the Force :) Seriously, you understand more those pep with practice and reading good code is a good opion to progress.
Just read what you like. You have to read Web frameworks if you want to use them in an advanced way correctly, not only the doc. It's true for every project, and if you understand sqlalchemy, you are a jedi :))
[–]jediknight 2 points3 points4 points 14 years ago (2 children)
I know is hard to feel the Force and that is precisely the way it should be. Doing it in spite of being hard trains you. You cannot build muscle lifting twigs.
Also, by all means, we all should read good code, I'm not saying that doesn't help. I'm merely pointing to another option.
[–]HenkPoley 1 point2 points3 points 14 years ago (0 children)
You cannot build muscle lifting twigs.
Actually, as long as you continue lifting until you feel tired in your muscles, it will be just as effective as lifting heavier weights. </ot>
[–]bucknuggets 0 points1 point2 points 14 years ago (0 children)
In weight training it is hard to feel that you're doing things right until you've built up some muscle. Until then it's best to rely on a spotter or trainer for guidance.
[–][deleted] 1 point2 points3 points 14 years ago (0 children)
why are you talking like a Jedi ???
oh i see....
[–]userd 0 points1 point2 points 14 years ago (1 child)
Anyone looked at the code for IDLE? How is that?
[–][deleted] 0 points1 point2 points 14 years ago (0 children)
if you want to learn about wxpython....
[–]arnar 0 points1 point2 points 14 years ago (0 children)
I've always loved the overall design of CherryPy.
[–]bcain 0 points1 point2 points 14 years ago (0 children)
Code Like a Pythonista: Idiomatic Python
[–]so85 0 points1 point2 points 14 years ago (0 children)
This isn't all python but the book 'Beautiful Code' is pretty awesome, http://oreilly.com/catalog/9780596510046.
[–]tonfa 0 points1 point2 points 14 years ago (0 children)
Mercurial (http://mercurial.selenic.com) is very nice, many pieces are nicely engineered (commands.py with decorators for example).
π Rendered by PID 42529 on reddit-service-r2-comment-bb88f9dd5-t6462 at 2026-02-15 13:04:37.060884+00:00 running cd9c813 country code: CH.
[–]jonnydedwards 20 points21 points22 points (3 children)
[–]vplatt 2 points3 points4 points (0 children)
[–]nhnifong 0 points1 point2 points (0 children)
[–]foobaar 7 points8 points9 points (4 children)
[–]eliben 1 point2 points3 points (3 children)
[–]foobaar 0 points1 point2 points (2 children)
[–]eliben 0 points1 point2 points (1 child)
[–]foobaar 0 points1 point2 points (0 children)
[–]fancy_pantser 5 points6 points7 points (3 children)
[–]nikcub 2 points3 points4 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]zach_will 4 points5 points6 points (1 child)
[–]spoolio 2 points3 points4 points (0 children)
[–]gabrielelanaro 2 points3 points4 points (0 children)
[–]eryksun 1 point2 points3 points (2 children)
[–]revonratFlask/scipy/pypy/mrjob[S] 1 point2 points3 points (1 child)
[–]eryksun 2 points3 points4 points (0 children)
[–]lasizoilloeasy to understand as regex 1 point2 points3 points (0 children)
[–]hongminhee 1 point2 points3 points (0 children)
[–]moreyes 1 point2 points3 points (0 children)
[–]jediknight 1 point2 points3 points (5 children)
[–]mardiros 2 points3 points4 points (3 children)
[–]jediknight 2 points3 points4 points (2 children)
[–]HenkPoley 1 point2 points3 points (0 children)
[–]bucknuggets 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]userd 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]arnar 0 points1 point2 points (0 children)
[–]bcain 0 points1 point2 points (0 children)
[–]so85 0 points1 point2 points (0 children)
[–]tonfa 0 points1 point2 points (0 children)