Live data from Hacker News

Ask HN: Good Python codebases to read?

news.ycombinator.com

131–140 of 153 posts

Re: Ask HN: Good Python codebases to read?

#131

Peter Norvig's examples. They are quite short and include much explanation in addition to code. They also include tests and benchmarking code. http://norvig.com/lispy.html http://norvig.com/lispy2.html (Lisp interpreter) http://www.norvig.com/spell-correct.html (Spelling corrector) http://norvig.com/sudoku.html (Sudoku solver) Also his online course Design of Computer programs includes many short, well-explained Pyth…

Norvig's code have several qualities to praise Adherence to Python's best practices / pep-8 are not one of them

PEP 8 itself has the quote "a foolish consistency is the hobgoblin of small minds." It is not intended as a prescriptive standard that everyone needs to follow, just a recommendation.

Re: Ask HN: Good Python codebases to read?

#132
post #126

Earlier quoted context omitted.

> The former is absolutely identical to the latter Oh, really? Let's compare: >>> absolute_0 = lambda path: path if path.startswith('/') else '/' + path >>> def absolute_1(path): ... '''Return the absolute unix path from a given path name''' ... if not path.startswith('/'): ... path = '/' + path ... return path >>> import dis >>> dis.dis(absolute_0) 2 0 LOAD_FAST 0 (path) 3 LOAD_ATTR 0 (startswith) 6 LOAD_CONST 1 ('/…

Is there any reason to use your hackery instead of the canonical form? (Other than I-am-right-syndrome)

Not sure which part you're curious about. If it wasn't clear from elsewhere in this thread...

Lambda functions are most useful for very small, straightforward functions that return a value - especially in cases where you don't necessarily need to name or document them deeply, such as for passing as arguments to other functions (for example, sort/sorted).

So if you want terse code that only does what it needs to do and nothing more, pepper with lambdas as needed.

If you want to invent names for things just cause you like inventing them or need to document every single function you write (even if the code is simple enough to document itself), feel free to make all one-line returning functions in the fully named and documented format.

Re: Ask HN: Good Python codebases to read?

#133

Earlier quoted context omitted.

Don't let it turn you into a fucking pedant, though.

When it comes to maintaining standards in a code base, one needs to be a pedant.

The mentality of someone who thinks that an 89-character line that ends with " # noqa" is better than the 81-character line without that ending because now it passes flake8 is one I'll never understand.

Re: Ask HN: Good Python codebases to read?

#134

Earlier quoted context omitted.

I would add the Django project to that list as it's a very large, mature, and successful open source python project - https://github.com/django/django

Django's source is very high quality. Though due to the large scope of the project, there are necessarily many layers of indirection, which may be a bit daunting for someone who is just starting out. However reading the less abstract parts may help. For instance, the paginator is pretty self contained. https://github.com/django/django/blob/master/django/core/pag...

I disagree. A lot of code that does very little.

I prefer sklearn like https://github.com/scikit-learn/scikit-learn/blob/master/skl...

A lot of code that does a lot.

Bottle is nice on the web dev front.

https://github.com/bottlepy/bottle/blob/master/bottle.py

Re: Ask HN: Good Python codebases to read?

#135

Earlier quoted context omitted.

I would add the Django project to that list as it's a very large, mature, and successful open source python project - https://github.com/django/django

Django's source is very high quality. Though due to the large scope of the project, there are necessarily many layers of indirection, which may be a bit daunting for someone who is just starting out. However reading the less abstract parts may help. For instance, the paginator is pretty self contained. https://github.com/django/django/blob/master/django/core/pag...

I really like the API of the framework, unfortunately some of the core elements suffer from being extremely stateful code

The "self.thing = bar" in one function that only gets used in some other function ( or even worse something only used in a companion class) pattern is super prevalent.

Might just be me but I think a lot of the older code suffers from massive locality problems that makes debugging framework bugs super tricky

Re: Ask HN: Good Python codebases to read?

#136
post #43

Check out boto. It's Amazon's official library for interacting with AWS. It is written and tested well. I use it every day. https://github.com/boto/boto

Boto3 might also be worth a read. https://github.com/boto/boto3

Boto3 was made using a much more principled design approach, while Boto grew organically and frankly got a bit out of control. I love boto3, it makes AWS a joy to use.

Re: Ask HN: Good Python codebases to read?

#137
post #133

Earlier quoted context omitted.

When it comes to maintaining standards in a code base, one needs to be a pedant.

The mentality of someone who thinks that an 89-character line that ends with " # noqa" is better than the 81-character line without that ending because now it passes flake8 is one I'll never understand.

+1 to that.

Re: Ask HN: Good Python codebases to read?

#138

Jumping on the Kenneth Reitz train, you might check out The Hitchhiker's Guide to Python: http://docs.python-guide.org/en/latest/ He recommends the following Python projects for reading: * Howdoi ( https://github.com/gleitz/howdoi ) * Flask ( https://github.com/mitsuhiko/flask ) * Werkzeug ( https://github.com/mitsuhiko/werkzeug ) * Requests ( https://github.com/kennethreitz/requests ) * Tablib ( https://github.com/k…

SQLAlchemy is one of my favourite larger python codebases: https://github.com/zzzeek/sqlalchemy

Re: Ask HN: Good Python codebases to read?

#139

NLTK: https://github.com/nltk/nltk with the documentation at http://www.nltk.org . I found the code easy to follow through. I referred to it when adding tests for tokenizers in a common lisp NLP application: https://github.com/vseloved/cl-nlp/ .

Agreed. NLTK's value is not that it should be your go-to source for NLP algorithms -- when there's a specific task you need to accomplish, there'll be a specific solution by now that works better than NLTK.

NLTK's value is that it shows you how to write NLP algorithms, and gives you an understandable starting point when you need to do something that nobody has implemented yet.

Re: Ask HN: Good Python codebases to read?

#140

I would also add *Twisted ( https://github.com/twisted/twisted ) For async python.

I disagree. Twisted is a sprawling codebase, it started as a game library that turned into an async library along the way, you need to read books to get the full documentation, and some of it doesn't even have docstrings or comments.
Post reply on HN