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…
Ask HN: Good Python codebases to read?
111–120 of 153 posts
Re: Ask HN: Good Python codebases to read?
#112Re: Ask HN: Good Python codebases to read?
#113Earlier 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 ('/…
Spare us the half-baked hackery. List comprehensions and generator expressions have replaced all need for map, filter, and lambdas, and are far more readable. For someone new to Python, halfway through LPTHW, they don't need those things. Hey, maybe you can help me decipher this, I've always wondered exactly what's going on here: https://docs.python.org/2/faq/programming.html#is-it-possibl... # Mandelbrot set print (…
I would say that is debatable. Coming from an FP background, I use map, filter and lambdas nearly all of the time because I find it more readable and can easily reason about the code. I have seen some two line list comprehensions and they are far harder for me to read and understand.
Re: Ask HN: Good Python codebases to read?
#114Earlier quoted context omitted.
Spare us the half-baked hackery. List comprehensions and generator expressions have replaced all need for map, filter, and lambdas, and are far more readable. For someone new to Python, halfway through LPTHW, they don't need those things. Hey, maybe you can help me decipher this, I've always wondered exactly what's going on here: https://docs.python.org/2/faq/programming.html#is-it-possibl... # Mandelbrot set print (…
> Spare us the half-baked hackery. Ad hominem? I guess I win. > List comprehensions and generator expressions have replaced all need for map, filter, and lambdas Please explain how list comprehensions and generators have replaced the need for lambdas. >>> sorted(((x, -(x**2)) for x in xrange(10) if 0 == x % 2), key=lambda item: item[1]) [(8, -64), (6, -36), (4, -16), (2, -4), (0, 0)] Your "distaste" of functional pro…
>>> [(b, a) for a, b in sorted(((-(x2), x) for x in xrange(10) if 0 == x % 2))]
[(8, -64), (6, -36), (4, -16), (2, -4), (0, 0)]
However, ocasionally you still need a more complex sorting function. So lambdas are still handy, IMO.
Re: Ask HN: Good Python codebases to read?
#115Earlier quoted context omitted.
requests is very useful, but it always gets mentioned as a good python codebase and I'm not sure I agree. One example: The first thing many users will do is requests.get? Which tells them that it takes some kwargs, but doesn't tell them what those kwargs are. It's easy, especially for a newcomer, to read "optional arguments that `request` takes" and fail to understand that they should look up the docs on (not-really-…
> requests.get? I was using Python for 8 years and IPython for somewhat 5 years if my memory serves me right but today I have learned that you can invoke help on an object by appending '?'. I guess I might delve into IPython documentation sometime. Thank you for lengthy and detailed explanation.
Re: Ask HN: Good Python codebases to read?
#116http://dirtsimple.org/2007/01/where-zope-leads-python-follow...
Re: Ask HN: Good Python codebases to read?
#117Peter 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…
His coding style is not common to most writers of Python. He's using overly terse, poorly descriptive variable names, not using multiline strings for docstrings, not indenting where he should, and one-lining if/elif statements and function definitions. This style does not contribute to readability. This is not how I would want someone just learning Python to learn it.
For instance, I find this unnecessarily difficult to read.
>>> 0 if True else 1 if True else 2
0
But breaking it up like this keeps it reasonably concise, while retaining readability.
if True:
a = 0 if True else 1
else:
a = 2
print(a)
They can also be combined with comprehensions, which can be useful.>>> import random
>>> ['a' if random.choice((True, False)) else 'b' for _ in range(6)]
['a', 'a', 'a', 'a', 'a', 'b']
Re: Ask HN: Good Python codebases to read?
#118*Twisted (https://github.com/twisted/twisted)
For async python.
Re: Ask HN: Good Python codebases to read?
#119Jumping 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…
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
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...
Re: Ask HN: Good Python codebases to read?
#120It's especially interesting because it takes advantage of new Python features like asyncio.