Python RNA getting the names of Vector axes. (eg "g" is color[1]) I've been playing around with DriverTarget data_path in a script. The data path, from the target.id object for the x location could be either "location.x" or "location[0]"

Is there a way of determining the name of the axes in different vector classes, like Vector ("xyz"), Quaternion("wxyz"), Color("rgb") ... or "hsv" and so on.

Currently I'm just hardcoding a lookup table.
Guess you've tried this already, so forgive me if it doesn't suit your needs. It's also using hardcoding via a dictionary, the test runs based on the type of the property and the axis to test on:

import bpy
from mathutils import Vector, Color, Euler, Quaternion


classMap = {
    Vector:'xyz',
    Color:'rgb',
    Euler:'xyz',
    Quaternion:'wxyz'
}


def returnIndex(_driverProp, _axis):
    dictVal = classMap[type(_driverProp)]
    return(dictVal.index(_axis))

print (returnIndex(bpy.context.object.rotation_quaternion, 'y'))