9

How can I document my custom Python functions in QGIS?

I would like to offer users help for functions I wrote for them:

enter image description here

I've tried adding a docstring:

enter image description here

But whenever I click Load an error message is displayed:

enter image description here

The error message clearly shows an indentation error, which does not correspond to my actual code.

1 Answer 1

8

What you are doing is the correct way to document your custom function.
The error you are encountering is because by default when you write a function in the Function Editor, the indentation before the return statement is that of 4 spaces characters and not 'tab space'. Just check if that is the case. The indentation should be consistent (either only spaces or tab space).

2
  • @ nash is right. I just tested the function and there's an error only when using a tab space instead of 4 spaces. +1, good answer!
    – mgri
    Mar 21, 2017 at 18:32
  • Good thinking! This means that the error message is correct as well. It is strange that sometimes, but not always, when you hit Enter QGIS uses a tab instead of space characters, meaning that QGIS adds an error by default. Although I cannot figure out when exactly it doesn’t do it correctly. Mar 28, 2017 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.