[Qgis-developer] Python plugins style guide

Martin Dobias wonder.sk at gmail.com
Tue Dec 28 04:58:13 EST 2010


On Sun, Dec 26, 2010 at 12:27 AM, Ricardo Filipe Soares Garcia da
<ricardo.garcia.silva at gmail.com> wrote:
> Hi list
>
> I have been working with Luiz Motta in the 'Custom db query' plugin
> and we came about the dilemma of how to best format our Python code.
>
> Looking around the QGIS wiki, we found the developers manual [1] and
> read through the coding guidelines, but the rules defined in it are
> for C++ programming and for QGIS core. We couldn't find anything
> related to Python and plugins.
>
> Has this been debated in the past? Is there a recommended style for
> formatting Python code in QGIS plugins?
> I usually follow the recommendation in the PEP8 [2], the official
> style guide for Python. But Luiz argues (a valid point I guess) that
> if we were to follow the C++ standard it would be more consistent with
> the rest of the code.

Hi Ricardo

I would recommend to use the Python style guide for plugins code.
After all, our c++ style cannot be applied in many cases, for example,
where to put opening and closing braces or naming of member variables
(mFoo in c++, naturally self.foo in python).

Also PyQt4 authors tend to "pythonize" the api, AFAIK pyqt for python3
will automatically convert QString to python (unicode) strings etc. Of
course there is a doubt whether to use Qt or python library for some
functionality found in both. This is just a matter of taste and
personally I would choose python library because typically it's less
verbose and more elegant.

Regards
Martin


More information about the Qgis-developer mailing list