wiki:ChimeraPythonStyle

Version 2 (modified by Darren Weber, 16 years ago) ( diff )

--

Chimera Python Style Guide

There is no generally accepted convention for coding style in Chimera. I follow an interpretation of the python style guidelines by Guido, see the snippet below and the full spiel at: ​http://www.python.org/dev/peps/pep-0008/

My style is 4 spaces for each indentation level (no tabs). My .vimrc contains:

" global settings
set tabstop=4
set shiftwidth=4
set expandtab
" python settings
autocmd BufRead,BufNewFile *.py set ft=python ai sw=4 ts=4 sta et fo=croql foldmethod=indent

For emacs, here's a good blog on useful python tools: ​http://jasonmbaker.com/7-tools-for-working-with-python-in-emacs-and.

It's possible to insert a mode line into each file to override user editor settings. The first line of the file might contain something like this (which should work for both emacs and vim):

# -*- coding: ISO-8859-1; mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=ISO-8859-1:ft=python:et:sw=4:ts=4:sts=4
### BEGIN PEP8 snippet:
Indentation

    Use 4 spaces per indentation level.

    For really old code that you don't want to mess up, you can continue to
    use 8-space tabs.

  Tabs or Spaces?

    Never mix tabs and spaces.

    The most popular way of indenting Python is with spaces only.  The
    second-most popular way is with tabs only.  Code indented with a mixture
    of tabs and spaces should be converted to using spaces exclusively.  When
    invoking the Python command line interpreter with the -t option, it issues
    warnings about code that illegally mixes tabs and spaces.  When using -tt
    these warnings become errors.  These options are highly recommended!

    For new projects, spaces-only are strongly recommended over tabs.  Most
    editors have features that make this easy to do.

...

Encodings (PEP 263)

    Code in the core Python distribution should aways use the ASCII or
    Latin-1 encoding (a.k.a. ISO-8859-1).  For Python 3.0 and beyond,
    UTF-8 is preferred over Latin-1, see PEP 3120.


### END PEP8 snippet:
Note: See TracWiki for help on using the wiki.