QGIS Python-Konsole "Indentation Error", Python-Editor kein "Indentation Error"
Hallo Liste, mir ist aufgefallen, dass die Python-Konsole in QGIS (3.22) bei Leerzeilen im Code "IndentationError" meldet, während der Python-Editor dasselbe Script ohne Fehlermeldung verarbeitet. Es handelt sich um einzelne Leerzeilen gefolgt von einem Kommentar, die ich z.B. im Verlauf einer for-Schleife wegen der Übersichtlichkeit eingefügt habe. Einen Beispiel-Ausschnitt aus dem Script siehe unten. In dem Beispiel haben die Leerzeilen keine Einrückung. Ich füge das gesamte Script per copy & paste in die Konsole bzw. den Editor ein. In der Konsole führt es zur genannten Fehlermeldung. Wenn das Script dagegen aus dem Editor heraus gestartet wird, läuft es fehlerfrei. Gibt es dafür eine Erklärung? Wo im Code Einrückungen nötig sind, sind sie alle mit Tabulator(en) gesetzt, keine Leerzeichen. ------------------------------------------------------------------------------------------- # Iterating over the input layer : for m in municip.getFeatures(): inh_center = m['EWZ'] # central municipalites with 0 inhabitants must be excluded; the value of "center_pos" will be set to -1. if inh_center == 0: center_pos = -1 dict = {m.fieldNameIndex('center_pos'):center_pos} municip.dataProvider().changeAttributeValues({m.id(): dict}) # Extract by location: else: key = m['AGS'] municip.selectByExpression('\"AGS\" = ' + str(key), QgsVectorLayer.SetSelection) result = processing.run("qgis:extractbylocation",{'INPUT':QgsProcessingFeatureSourceDefinition(municip.id(),False),'PREDICATE':4,'INTERSECT':QgsProcessingFeatureSourceDefinition(municip.id(),True),'OUTPUT':'memory:'}) extracted = result['OUTPUT'] count_all = extracted.featureCount() countsmall = 0 ---------------------------------------------------------------------------------------- Viele Grüße, Christiane -- Christiane Enderle, MSc Philipps-Universität Marburg Fachbereich Geographie Deutschhausstr. 10 35037 Marburg Tel. +49 (0)6421-2822179 Fax +49 (0)6421-2828950
participants (1)
-
Chr. Enderle