Live data from Hacker News

Ask HN: Good Python codebases to read?

news.ycombinator.com

121–130 of 153 posts

Re: Ask HN: Good Python codebases to read?

#121

Earlier quoted context omitted.

OK, maybe I will open an issue. The obvious concern is how to avoid duplicating the text among the various HTTP verb functions. In theory python allows the docstring to be manipulated via __doc__. However I don't think there is a precedent for using that mechanism to avoid duplication of docstring content that is considered good style, but perhaps someone could correct me if that is wrong.

You'd probably want to make a metaclass that handled the manipulation of __doc__ for shared verbs if you didn't want to duplicate the data too much.

OK, but in requests they are top-level functions, not methods. Is there anything wrong with the below? I don't think I've seen it done.

  __shared_docstring_content = """
  bar
  baz
  """

  def f():
      "f docstring"
      pass

  f.__doc__ += __shared_docstring_content


  def g():
      "g docstring"
      pass

  g.__doc__ += __shared_docstring_content

Re: Ask HN: Good Python codebases to read?

#122

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...

definitely agree.. I recently looked at the management command code as a reference when building some non-django scripts that use python argparse...

https://github.com/django/django/blob/master/django/core/man...

Re: Ask HN: Good Python codebases to read?

#123
post #103
post #91

Earlier quoted context omitted.

Well, between a run of the mill programmer who happens to indent where he/she should vs Norvig, I will likely choose the latter If I could. Reminds me of that blog thread where this design pattern guru hemmed and hawed from his high horse over several posts about how to write constrained based solvers and still did not get to a piece of code that actually solved the problem, whereas Norvig just posted a simple soluti…

>Well, between a run of the mill programmer who happens to indent where he/she should vs Norvig, I will likely choose the latter If I could. Right. >Reminds me of that blog thread where this design pattern guru hemmed and hawed from his high horse I read a similar story a while ago. Two programmers are given the task of writing a program for some non-trivial problem. One of them, Hoity Toity Harry, tries to apply man…

Speaking of which, I once saw a user review of Norvig's book PAIP complaining about the unsophisticated code -- no monads, etc. (I forget what other patterns the reviewer wanted to see.)

Re: Ask HN: Good Python codebases to read?

#124

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…

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

Is the Django project Pythonic? I mean, on the one hand, Python is the language of bells and whistles builtin. On the other hand, packages are encouraged to be simple and to the point.

Whilst this wasn't a discussion on which framework is best (and I'm not a Web dev by trade either), I must say I turn to Flask, as I find the API more Pythonic.

I guess what I'm trying to say is that the Django source code is probably great, but the less heavyweight packages/frameworks the better. Learn Pythonic API design from somewhere else.

Re: Ask HN: Good Python codebases to read?

#125

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: I also learned a lot from nltk too, esp. freqdist/probdist as well as the classifiers in nltk and sklearn

Re: Ask HN: Good Python codebases to read?

#126

Earlier quoted context omitted.

The former is absolutely identical (semantically) to the latter, with two exceptions: 1) the former function does not know its own name and 2) the latter function can (and should) be documented with a docstring. I find the latter eminently more readable, and I work daily in a code base under development by 3000 Python developers for over 5 years. Considering that the creator of the Python language considered getting…

> 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)

Re: Ask HN: Good Python codebases to read?

#128

A large Python project that I haven't seen mentioned by others but that I find to be particularly well written and designed is the Pyramid web framework. * https://github.com/Pylons/pyramid/

I agree with you. Pyramid is one of the most well designed codebase that I know.

Re: Ask HN: Good Python codebases to read?

#130

Earlier quoted context omitted.

You'd probably want to make a metaclass that handled the manipulation of __doc__ for shared verbs if you didn't want to duplicate the data too much.

OK, but in requests they are top-level functions, not methods. Is there anything wrong with the below? I don't think I've seen it done. __shared_docstring_content = """ bar baz """ def f(): "f docstring" pass f.__doc__ += __shared_docstring_content def g(): "g docstring" pass g.__doc__ += __shared_docstring_content

I would do simply """f docstring\n%s""" % _shared_docstring, no need for a separate concatenation. However, I wonder whether sphinx would handle this.
Post reply on HN