Question: Could anybody provide an example how to get the attributes of selected features?

I tried the following code in the Python Console : but I'm stuck at the point where I'd like to get the attributes:

```py
from qgis.utils import iface

canvas = iface.mapCanvas()
cLayer = canvas.currentLayer()
selectList = []

if cLayer:
    count = cLayer.selectedFeatureCount()
    print (count)
    selectedList = layer.selectedFeaturesIds()

    for f in selectedList:
        # This is where I'm stuck
        # As I don't know how to get the Attributes of the features

```

Answer: 
This will work:

```py
layer = iface.activeLayer()

features = layer.selectedFeatures()

for f in features:
    print f.attributeMap()

```

In PyQGIS 3:

```py
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

```
There are also other approaches available:

Approach 1 : [`QgsAggregateCalculator`](https://qgis.org/api/3.16/classQgsAggregateCalculator.html#a51eb9f5752cf107d72266829a21cf2fa) with `ArrayAggregate`
-----------------------------------------------------------------------------------------------------------------------------------------------------------

> 
> Available aggregates to calculate.
> 
> 
> Not all aggregates are available for all field types.
> 
> 
> 

This approach is available since QGIS 2.16.

```py
layer = iface.activeLayer()

# creates a memory layer of original layer exclusively with all selected features in it
temp_layer = layer.materialize(QgsFeatureRequest().setFilterFids(layer.selectedFeatureIds()))

# specify your target field
result = temp_layer.aggregate(QgsAggregateCalculator.ArrayAggregate, "your_field")[0]

# prints an output list
print(result)

```

Approach 2 : [`QgsVectorLayerUtils`](https://qgis.org/pyqgis/3.2/core/Vector/QgsVectorLayerUtils.html#module-QgsVectorLayerUtils)
---------------------------------------------------------------------------------------------------------------------------------

> 
> Contains utility methods for working with QgsVectorLayers.
> 
> 
> 

This approach is available since QGIS 3.

```py
layer = iface.activeLayer()

 # creates a memory layer of original layer exclusively with all selected features in it
temp_layer = layer.materialize(QgsFeatureRequest().setFilterFids(layer.selectedFeatureIds()))

# specify your target field
result = QgsVectorLayerUtils.getValues(temp_layer, "your_field")[0]

# print an output list
print(result)

```

---

**References:**

* [Creating Vector layer from selected features with PyQGIS](https://gis.stackexchange.com/questions/80292/how-can-i-create-a-vector-layer-from-selected-features-with-pyqgis)