Skip to main content
added 68 characters in body
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148

You can use field_names = [field.name() for field in layer.fields()] toTo get field names with fields() method or other field properties (length, type, comment, ...). you can use:

field_names = [field.name() for field in layer.fields()]
# ['id', 'attr1', 'attr2', 'attr3']

If you just need names, it's sufficient to use field_names = layer.fields().names():

field_names = layer.fields().names()
# ['id', 'attr1', 'attr2', 'attr3']

You can use field_names = [field.name() for field in layer.fields()] to get field names or other field properties (length, type, comment, ...).

If you just need names, it's sufficient to use field_names = layer.fields().names()

To get field names with fields() method or other field properties (length, type, comment, ...) you can use:

field_names = [field.name() for field in layer.fields()]
# ['id', 'attr1', 'attr2', 'attr3']

If you just need names, it's sufficient to use:

field_names = layer.fields().names()
# ['id', 'attr1', 'attr2', 'attr3']
Source Link
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404

You can use field_names = [field.name() for field in layer.fields()] to get field names or other field properties (length, type, comment, ...).

If you just need names, it's sufficient to use field_names = layer.fields().names()