Macro/Guida a Python/Errori comuni
TDF LibreOffice Blog comunitari Weblate(traduci) Autori Nextcloud Redmine Ask LibreOffice | Donazione
Errori comuni
Per cortesia: Python non è Basic e questo è un bene.
Indentazione
L'errore più comune per chi inizia a sviluppare delle macro in Python, o ci arriva dal Basic, è quello di indentazione. Python ha una sintassi molto rigida.
Se questo funziona in Basic
Sub test()
If True Then
MsgBox "Hello"
End If
End Sub
This does not work in Python
def test():
if True:
print('Hello')
return
The correct version is:
def test():
if True:
print('Hello')
return
Many instructions in Python are determined by the indentation. In other programming languages the indentation in code is for readability only, the indentation in Python is very important and validates many logical instructions.
Tabulazioni o spazi
Per l'indentazione potete usare delle tabulazioni o degli spazi. La PEP 8 raccomanda l'utilizzo degli spazi, ma di non usarli in combinazione con le tabulazioni. Python 3 non permette l'indentazione con l'uso promiscuo di spazi e tabulazioni e siete pregati di non usare più Python 2.