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

This will work:

features = layer.selectedFeatures()
for f in features:
    print f.attributeMap()
layer = iface.activeLayer()

features = layer.selectedFeatures()

for f in features:
    print f.attributeMap()

In PyQGIS 3:

layer = iface.activeLayer()

features = layer.selectedFeatures()

for f in features:
    # refer to all attributes
    print (f.attributes()) # results in [3, 'Group 1', 4.6]

for f in features:
    # refer to a specific values of a field index
    print(f.attribute(1)) # results in Group 1

This will work:

features = layer.selectedFeatures()
for f in features:
    print f.attributeMap()

This will work:

layer = iface.activeLayer()

features = layer.selectedFeatures()

for f in features:
    print f.attributeMap()

In PyQGIS 3:

layer = iface.activeLayer()

features = layer.selectedFeatures()

for f in features:
    # refer to all attributes
    print (f.attributes()) # results in [3, 'Group 1', 4.6]

for f in features:
    # refer to a specific values of a field index
    print(f.attribute(1)) # results in Group 1
Source Link
Nathan W
  • 35k
  • 5
  • 99
  • 148

This will work:

features = layer.selectedFeatures()
for f in features:
    print f.attributeMap()