Python Coding Standards for NDG

Documentation Standards

In all scripts we should make the best use of module level doc strings as well as method and class strings.

e.g. for

 '''some stuff about module '''
  def exitNicely(msg):
     ''' here is a method string: this method produce a nice informative exit message ...
     print __doc__
     print msg

General Coding Level Standards

  • All classes should start with a capital
  • All methods and functions should not start with a capital
  • packages should not start with a capital
  • use CamelCase for anything that is exposed ...
  • methods with intent local should be ._blah
  • methods to be not exposed should be .blah (recognising that subclasses would not be able to use blah).
  • all methods should have a docstring
  • we will use epydoc

Python Guidance

Usefile ideas:

For line length:

 a=b+c+d # or
   d]) # or
 a=(b c
 a = ('the cat '
     'sat '
     'on the mat')

This is nice too:

print >> sys.stderr,stuff goes to error ...

And this is an abomination:

y = (x>10) and 5 or 7

will make y 5 if x>10 ...