Changes between Version 6 and Version 7 of Submitting/Python
- Timestamp:
- 06/23/14 16:58:35 (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Submitting/Python
v6 v7 80 80 Note that Python determines nesting based upon indentation, so it is quite crucial to be consistent, i.e. use given rules. 81 81 82 Make sure a new line is at the end of each file and there are no trailing spaces.83 84 82 Do not fix (intentionally or unintentionally) existing style issues in code (at lines) you are not changing. 85 83 If you are fixing style issues, do it in a separate commit. 86 84 87 Use named parameters in functions (without space around '='), e.g. 88 89 {{{ 90 !python 85 Summary 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 95 angle = angle * pi / 180 96 # not this: 97 angle = angle*pi/180 98 }}} 99 100 * Do not use space around parentheses: 101 102 {{{ 103 #!python 104 grass.run_command('g.region', rast='myrast') 105 # not this: 106 grass.run_command( 'g.region', rast='myrast' ) 107 }}} 108 109 * Do not use space around '=' in a keyword argument: 110 111 {{{ 112 #!python 113 grass.run_command('g.region', rast='myrast') 114 # not this: 115 grass.run_command( 'g.region', rast = 'myrast' ) 116 }}} 117 118 * Use space after comma: 119 120 {{{ 121 #!python 122 a = [1, 2, 3] 123 # not this: 124 a = [1,2,3] 125 }}} 126 127 * Good practice is to use named parameters in functions: 128 129 {{{ 130 #!python 91 131 dlg = wx.FileDialog(parent=self, message=_("Choose file to save current workspace"), 92 132 wildcard=_("GRASS Workspace File (*.gxw)|*.gxw"), style=wx.FD_SAVE) 93 }}} 94 95 instead of 96 97 {{{ 98 !python 133 # not this: 99 134 dlg = 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 }}} 107 137 == Writing the code == 108 138