Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #101794 > unrolled thread

Python best practices

Started bygliesian66@gmail.com
First post2016-01-15 17:19 -0800
Last post2016-01-16 15:16 -0500
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Python best practices gliesian66@gmail.com - 2016-01-15 17:19 -0800
    Re: Python best practices Steven D'Aprano <steve@pearwood.info> - 2016-01-16 13:32 +1100
    Re: Python best practices Bob Gailer <bgailer@gmail.com> - 2016-01-16 14:41 -0500
    Re: Python best practices Felix Almeida <felix.almeida@gmail.com> - 2016-01-16 15:16 -0500

#101794 — Python best practices

Fromgliesian66@gmail.com
Date2016-01-15 17:19 -0800
SubjectPython best practices
Message-ID<a746ac38-3e2f-4af6-aa6c-6512cda62cb7@googlegroups.com>
Are there any good resources on python best practices?  e.g., articles

Thanks,
Robert

[toc] | [next] | [standalone]


#101795

FromSteven D'Aprano <steve@pearwood.info>
Date2016-01-16 13:32 +1100
Message-ID<5699abce$0$1597$c3e8da3$5496439d@news.astraweb.com>
In reply to#101794
On Sat, 16 Jan 2016 12:19 pm, gliesian66@gmail.com wrote:

> Are there any good resources on python best practices?  e.g., articles


If you come from a Java background, you should read these two articles:

http://dirtsimple.org/2004/12/python-is-not-java.html
http://dirtsimple.org/2004/12/java-is-not-python-either.html

Everybody should read this:

https://realpython.com/blog/python/the-most-diabolical-python-antipattern/

Stop writing classes:

https://www.youtube.com/watch?v=o9pEzgHorH0

Start writing classes:

http://lucumr.pocoo.org/2013/2/13/moar-classes/

Contradiction? No, not really. You should understand when to write a class
when not to write a class. If you force everything to be in a class, you're
living in the Kingdom of Nouns:

http://steve-yegge.blogspot.com.au/2006/03/execution-in-kingdom-of-nouns.html

(discusses the Java model of "everything must be in a class")


Nearly everything by Raymond Hettinger, starting with these:

https://www.youtube.com/watch?v=OSGv2VnC0go
https://www.youtube.com/watch?v=wf-BqAjZb8M

Read the Python source code:

https://rhettinger.wordpress.com/2011/01/28/open-your-source-more/

(Older modules might not show "best practice" any more, but you can still
learn something from them.)

At the interactive interpreter, read the Zen of Python:

import this



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#101816

FromBob Gailer <bgailer@gmail.com>
Date2016-01-16 14:41 -0500
Message-ID<mailman.46.1452973301.15297.python-list@python.org>
In reply to#101794
On Jan 15, 2016 8:20 PM, <gliesian66@gmail.com> wrote:
>
> Are there any good resources on python best practices?  e.g., articles

What programming experience do you have? I'm thinking of languages.

Here are a few of my guidelines - most not Python specific:

Keep logic and data separate.

Comment early and often - but don't comment the obvious.

Use meaningful names.

Read the manuals.

Get familiar with modules. Someone has likely already solved the problem.

Do not override built-in names.

Follow these email lists.

Avoid things like "if valid == True:".
"if valid:" is sufficient.

Read the manuals.

When asking for help:
  Use a problem-specific subject.
  Use plain text so code keeps indentation
  Mention your Python version and OS.
  Include any traceback.

If something is not clear try it in the interactive window.

Dictionaries are very useful. Get familiar with them.

HTH.

[toc] | [prev] | [next] | [standalone]


#101817

FromFelix Almeida <felix.almeida@gmail.com>
Date2016-01-16 15:16 -0500
Message-ID<n7e89f$8m4$1@dont-email.me>
In reply to#101794
Pylint is your friend: http://www.pylint.org/

If you already know a bit about the language then a good place to start 
is the Google Python Style Guide: 
https://google.github.io/styleguide/pyguide.html



On 15/01/16 08:19 PM, gliesian66@gmail.com wrote:
> Are there any good resources on python best practices?  e.g., articles
>
> Thanks,
> Robert
>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web