Changes between Version 6 and Version 7 of Submitting/Python


Ignore:
Timestamp:
06/23/14 16:58:35 (10 years ago)
Author:
annakrat
Comment:

list main pep8 rules

Legend:

Unmodified
Added
Removed
Modified
  • Submitting/Python

    v6 v7  
    8080Note that Python determines nesting based upon indentation, so it is quite crucial to be consistent, i.e. use given rules.
    8181
    82 Make sure a new line is at the end of each file and there are no trailing spaces.
    83 
    8482Do not fix (intentionally or unintentionally) existing style issues in code (at lines) you are not changing.
    8583If you are fixing style issues, do it in a separate commit.
    8684
    87 Use named parameters in functions (without space around '='), e.g.
    88 
    89 {{{
    90 !python
     85Summary of the most important rules:
     86 * Make sure a new line is at the end of each file.
     87
     88 * Use three double quotes for docstrings (`"""..."""`). Use double quotes for translatable (user visible) strings, single quotes for the rest.
     89
     90 * Remove trailing whitespace from the end of lines. Empty lines should not contain any spaces.
     91 * Put space between operators:
     92
     93{{{
     94#!python
     95angle = angle * pi / 180
     96# not this:
     97angle = angle*pi/180
     98}}}
     99
     100 * Do not use space around parentheses:
     101
     102{{{
     103#!python
     104grass.run_command('g.region', rast='myrast')
     105# not this:
     106grass.run_command( 'g.region', rast='myrast' )
     107}}}
     108
     109 * Do not use space around '=' in a keyword argument:
     110
     111{{{
     112#!python
     113grass.run_command('g.region', rast='myrast')
     114# not this:
     115grass.run_command( 'g.region', rast = 'myrast' )
     116}}}
     117
     118 * Use space after comma:
     119
     120{{{
     121#!python
     122a = [1, 2, 3]
     123# not this:
     124a = [1,2,3]
     125}}}
     126
     127 * Good practice is to use named parameters in functions:
     128
     129{{{
     130#!python
    91131dlg = wx.FileDialog(parent=self, message=_("Choose file to save current workspace"),
    92132                    wildcard=_("GRASS Workspace File (*.gxw)|*.gxw"), style=wx.FD_SAVE)
    93 }}}
    94 
    95 instead of
    96 
    97 {{{
    98 !python
     133# not this:
    99134dlg = wx.FileDialog(self, _("Choose file to save current workspace"),
    100                     _("GRASS Workspace File (*.gxw)|*.gxw"), wx.FD_SAVE)
    101 }}}
    102 
    103 Use three double quotes for docstrings (`"""..."""`).
    104 Use double quotes for translatable (user visible) strings, single quotes for the rest.
    105 
    106 
     135                     _("GRASS Workspace File (*.gxw)|*.gxw"), wx.FD_SAVE)
     136}}}
    107137== Writing the code ==
    108138