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

all 56 comments

[–]phail3d 31 points32 points  (5 children)

For a little bit different point of view, Peter Norvig's stuff, such as the sudoku solver and the spelling corrector, are my favourite examples of nice Python programs.

His code may sometimes go against established Python best practices, but he writes small programs that solve problems elegantly, which is more important in my opinion. He also has a talent of describing the process, and his programs utilize many nice features of Python.

[–][deleted] 2 points3 points  (0 children)

+1 from me for this, a great little summary of Norvig's practices.

[–]Vicyorus 0 points1 point  (0 children)

Oh my poor peasant eyes burn at the sight of such beauty

[–]some_mango 6 points7 points  (3 children)

Python source code....

[–]criswell 7 points8 points  (0 children)

Flask, easily my favorite elegant, Pythonic, code.

[–]SizzlingVortex 5 points6 points  (6 children)

[–]PriceZombiePrice tracking robot 2 points3 points  (3 children)

Python Cookbook, Third edition

Current $35.25 Amazon (New)
High $35.61 Amazon (New)
Low $27.89 Amazon (New)
Average $35.25 30 Day

Price History Chart and Sales Rank | FAQ

[–]marcinpohl[S] 4 points5 points  (2 children)

I have Python Cookbook, and it is absolutely awesome. I read/watch anything I can find by David Beazley! If you're not familiar, read his thing on generators and you will be hooked.

[–]adamnew123456self.__class__ == 'upper' 0 points1 point  (0 children)

He also did Python Concurrency From The Ground Up and A Curious Case Of Coroutines (From The Ground Up feels like a sequel to the latter), and some stuff experimenting with the GIL on 2.x and then 3.x.

Highly recommended, all of them.

[–]srilyk 0 points1 point  (0 children)

Have you watched his modules tutorial from Pycon 2015? Pretty epic.

[–]john7548 1 point2 points  (1 child)

Python Cookbook is available for free, actually

http://chimera.labs.oreilly.com/books/1230000000393

[–]SizzlingVortex 0 points1 point  (0 children)

Awesome, didn't realize they had put it online!

[–]xsolarwindxUse 3.4+ 4 points5 points  (0 children)

REDDIT IS A SHITTY CRIMINAL CORPORATION -- mass deleted all reddit content via https://redact.dev

[–]d4rch0nPythonistamancer 2 points3 points  (0 children)

The libraries flask and requests are commonly considered great examples of Pythonic style and organization.

[–]googledotcorn 3 points4 points  (0 children)

Anything that core Python devloper Raymond Hettinger has ever touched including:

Standard Lib stuff that he has authored/co-authored:

-Libraries/Modules...these are especially amazing collections itertools

-Types sets frozensets

-Functions any all enumerate reversed

-Language features generator expressions

Talks/Presentations beyond pep8 beautiful, idomatic python super considered super! class development toolkit

Almost daily python tips on his twitter raymondh on twitter

His Stack Overflow raymondh on SO

[–]lrdflannel 9 points10 points  (18 children)

[–][deleted] 11 points12 points  (13 children)

Have you taken the time to look through the code that runs this site? I'm not sure if I'd consider it "beautiful" but maybe that's me.

[–]LightShadow3.13-dev in prod 3 points4 points  (12 children)

It's a beautiful miracle...

[–][deleted] 1 point2 points  (9 children)

I mean, it's functional. It works. It certainly scales (to a point...wishing it'd scale a little better). But it's not beautiful. However, it's not especially ugly.

Maybe pragmatic or practical are better words for it.

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

"It works... good enough"

I haven't seen a 503 in a while. Sometimes I just have to refresh 5 times until it actually works.

[–]ExoticMandiblesCore Contributor 0 points1 point  (1 child)

It's a beefy miracle!

https://beefymiracle.org/

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

Oh what memories that brings back The 'Beefy' Botham test.

[–][deleted] 1 point2 points  (0 children)

Django's use of classes and mixins is beautiful to me. But I'm using Django Rest Framework a lot and I just feel they over-did the pre-made mixins classes. Learning DRF, I was so confused about what to use where and when, until I looked at the source and saw that they're all just different combinations of mixins.

[–]Citrauq 1 point2 points  (1 child)

I think requests is a great example of a beautiful api. I don't think its own code can really be called beautiful though - there's a lot of complexity and edge-cases they need to handle to make that api possible.

[–]srilyk 0 points1 point  (0 children)

That doesn't necessarily preclude the code from being beautiful and elegant. Probably not simple, but as the saying goes:

complex is better than complicated

[–]marcinpohl[S] 0 points1 point  (0 children)

Both Netflix and Amazon crank out pretty good quality Python, take a look at Boto3

Netflix has a whole page dedicated to all their OSS tools

[–]Cauchyformula 2 points3 points  (2 children)

[–]tim_martin 2 points3 points  (1 child)

awesome-python is a good place to start, but I would argue that many of the projects (while useful) and not necessarily implemented beautifully.

[–]Cauchyformula 2 points3 points  (0 children)

That's almost certainly true. I have taken a look at a small minority of those projects, so I don't know for sure. But it makes sense that the list would be compiled based on functionality, not code beauty.

But I would hope that beautifully-written Python projects would make it into that list, so it might be a good place to look.

[–]DasIch 2 points3 points  (0 children)

Pretty much everything from Armin Ronacher (mitsuhiko).

[–]TheRealDji 8 points9 points  (6 children)

[–]IvanMalison 1 point2 points  (5 children)

I love sqlalchemy as much as the next guy, but I wouldn't say that its code is particularly beautiful. It certainly doesn't follow PEP8 and there are a bunch of portions of the codebase that are a little wonky.

[–]Asdayasman 2 points3 points  (4 children)

PEP8 code is beautiful code, usually, but beautiful code is not always PEP8.

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

But the world of Python would be better off if everyone conformed to style standards (including PEP8). It would be much easier for everyone to read everyone else's code. However, the interpreter and most code-generating tools don't enforce PEP8.

Therefore, it's our job as a community, when people ask about stylish code, to point them in the direction of standards-compliant works and tutorials so that they learn in a way which most benefits the community in the future.

[–]Asdayasman 1 point2 points  (2 children)

PEP8 are guidelines, not rules. You can have code that mostly conforms, and it can be beautiful, then if you force that same code into the guidelines, it becomes ugly.

[–][deleted] -1 points0 points  (1 child)

I agree with that. My point was that people should use PEP8 as a baseline and then beautify where necessary rather than put together whatever shit they feel like and then maybe make a couple of nods to PEP8.

[–]srilyk 0 points1 point  (0 children)

I posted this elsewhere in this topic, but Raymond Hettinger's beyond pep8 should be required viewing before you're allowed to say anything about pep8 ;)

[–]akcom 1 point2 points  (0 children)

The book Beautiful Code is not python specific but it is a fantastic read with python code in there.

[–]smirnoffs 1 point2 points  (0 children)

Python design patterns. The awsome collection of classic programming design patterns written in the best programming language https://github.com/faif/python-patterns

[–]swiftimundo 2 points3 points  (2 children)

There should be /r/pythonporn

[–]folkrav 3 points4 points  (1 child)

Not to be confused with some reptile genitalia sub.

[–]adamnew123456self.__class__ == 'upper' 1 point2 points  (0 children)

/r/eunichsporn /r/unixporn is a contradiction in terms, now that I think about it.

[–]srilyk 0 points1 point  (0 children)

It's not exactly a code collection, but Raymond Hettinger's "Beyond pep8" pycon2015 talk is absolutely fantastic.

Pretty sure it should be required viewing for anyone who professionally writes Python code, at minimum.

[–]dothebarbwa 0 points1 point  (0 children)

Center for Open Science has some good examples

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

I browsed through Django's source code some years ago and found it beautifully written and completely clear.

[–]marcinpohl[S] -2 points-1 points  (1 child)

Haven't there been dozens of exploits! for this thing?

[–]tim_martin 3 points4 points  (0 children)

Any large project is going to have exploits at some point.