I'm new using PyQGIS 3 and I'm wondering how to access the field information from a layer generated by script.
Inside my processAlgorithm
function I have the following:
alg_params = {
'EXPRESSION': parameters[self.IN_EXPRESSION],
'INPUT': parameters[self.IN_SHP],
'OUTPUT': parameters[self.OUT_SHP]
}
final_output = processing.run('native:extractbyexpression', alg_params, context=context, feedback=feedback, is_child_algorithm=True)['OUTPUT']
output_lyr = QgsVectorLayer(final_output, "output_testing", "ogr")
fields = output_lyr.fields()
fieldnames = [field.name() for field in fields]
print(fieldnames)
return {"result": final_output }
The algorithm itself is returning the right output, however I'm not able to access the fields during inside the code, the print
is returning me a empty list, however my final_output
DO have fields.
Someone, could give me a glimpse of what I've missed?
print(fields.names())
?print(final_output.fields().names())
?