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
Ask HN: Good Python codebases to read?
131–140 of 153 posts
Re: Ask HN: Good Python codebases to read?
#132Earlier 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)
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?
#133Earlier 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.
Re: Ask HN: Good Python codebases to read?
#134Earlier 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 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.
Re: Ask HN: Good Python codebases to read?
#135Earlier 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...
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?
#136Check 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
Re: Ask HN: Good Python codebases to read?
#137Earlier 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.
Re: Ask HN: Good Python codebases to read?
#138Jumping 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…
Re: Ask HN: Good Python codebases to read?
#139NLTK: 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/ .
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?
#140I would also add *Twisted ( https://github.com/twisted/twisted ) For async python.