Live data from Hacker News

Code Like a Pythonista: Idiomatic Python

python.net

31–40 of 59 posts

Re: Code Like a Pythonista: Idiomatic Python

#31
post #30

Can anyone suggest any other materials or resources in the same vein as this?

See http://www.quora.com/How-can-I-learn-to-program-in-Python/an...

Thanks for the reply -- I should have been more specific. I'm after something that similarly contrasts naive and idiomatic styles.

Re: Code Like a Pythonista: Idiomatic Python

#32
post #30

Earlier quoted context omitted.

See http://www.quora.com/How-can-I-learn-to-program-in-Python/an...

Thanks for the reply -- I should have been more specific. I'm after something that similarly contrasts naive and idiomatic styles.

You mean Python specifically or for other programming languages?

Re: Code Like a Pythonista: Idiomatic Python

#33
post #32

Earlier quoted context omitted.

Thanks for the reply -- I should have been more specific. I'm after something that similarly contrasts naive and idiomatic styles.

You mean Python specifically or for other programming languages?

Python, specifically.

Re: Code Like a Pythonista: Idiomatic Python

#34
post #32

Earlier quoted context omitted.

You mean Python specifically or for other programming languages?

Python, specifically.

  * Idioms and Anti-Idioms in Python (http://docs.python.org/howto/doanddont.html)
  * Python Idioms and Efficiency  (http://jaynes.colorado.edu/PythonIdioms.html)
  * Python Style Guide (http://www.python.org/dev/peps/pep-0008/)
  * Google Python Style Guide (http://google-styleguide.googlecode.com/svn/trunk/pyguide.html)
  * Pocoo Style Guide (http://www.pocoo.org/internal/styleguide/)

Re: Code Like a Pythonista: Idiomatic Python

#36

One thing that has always bugged me about PEP8 is the advice about trying to keep line length to I basically just completely ignore this part of the guidance, even though I know that in theory it makes it hard to edit code via a terminal. But this is not something we ever do in practice where I work - code on servers gets there only by being checked out of SVN. I personally find it incredibly irritating when I see pe…

The 80-char limit recommendation is a thing I regularly sin against; most of the time caused by a comment behind a statement.

Re: Code Like a Pythonista: Idiomatic Python

#37
post #4

He had me up until the part where he wrote an algorithm to specifically leave out the Oxford Comma. :) Kidding aside, this was a great read.

As he remarks, he doesn't take in account the corner cases. Suprisingly, or maybe not, his concatenation statement is similar to what I regularly use:

  def commalist(f, endword="and"):
      "Concatenate a list of strings in the form of 'Red, Yellow, Green and Blue'."
      if len(f) == 0:
          return ""
      elif len(f) == 1:
          return f[0]
      else:
          return ", ".join(f[:-1]) + " " + endword + " " + f[-1]

Re: Code Like a Pythonista: Idiomatic Python

#38

One thing that has always bugged me about PEP8 is the advice about trying to keep line length to I basically just completely ignore this part of the guidance, even though I know that in theory it makes it hard to edit code via a terminal. But this is not something we ever do in practice where I work - code on servers gets there only by being checked out of SVN. I personally find it incredibly irritating when I see pe…

People seem disregard this rule as "dated" without actually providing much argument! The reason is that with a larger screen you can get more than one file on the screen at once, and the usability of that massively trumps any minor linebreaking issues.

Re: Code Like a Pythonista: Idiomatic Python

#40

One thing that has always bugged me about PEP8 is the advice about trying to keep line length to I basically just completely ignore this part of the guidance, even though I know that in theory it makes it hard to edit code via a terminal. But this is not something we ever do in practice where I work - code on servers gets there only by being checked out of SVN. I personally find it incredibly irritating when I see pe…

I dislike the 80 character limit, too. But having no limit at all would be a disaster for readability.

I believe a 100 or 120 character limit is a nice compromise.

Post reply on HN