Project

General

Profile

Actions

Python Coding Standards » History » Revision 1

Revision 1/7 | Next »
Neil Voss, 03/19/2010 02:11 PM


Python Coding Standards

This document is a list of python coding standards. To add a new standard copy the template below and modify it.


Name of Coding Standard

Definition

What is the coding standard

Justification

Why is the coding standard important

Example

GOOD:

this is a good example code

BAD:

this is a bad example code


Python Coding Standards for AMI


Checking beginning or ending of strings

Definition

Use ''.startswith() and ''.endswith() instead of string slicing to check for prefixes or suffixes.

Justification

startswith() and endswith() are cleaner and less error prone.

Example

GOOD:

if foo.startswith('bar'): 

BAD:

if foo[:3] == 'bar':


Never use from module import *

Definition

Never use from module import *, use import module instead

Justification

It is hard to track where functions come from when import * is used

Example

GOOD:

import numpy
a = numpy.ones((3,3))

BAD:

from numpy import *
a = ones((3,3))

Updated by Neil Voss almost 15 years ago · 1 revisions