class AutonamingType(type):

    def __init__(cls, name, bases, attrs):
        for attrname, attrvalue in attrs.items():
            if getattr(attrvalue, '__autoname__', False):
                attrvalue.name = attrname
super(AutonamingType, cls).__init__(name, bases, attrs)


class NamedDescriptor(object):
    __autoname__ = True
name = None

def __get__(self, instance, instance_type):
    return self.name


class Foo(object, metaclass=AutonamingType):
    pass
bar = NamedDescriptor()
baaz = NamedDescriptor()
lilfoo = Foo()
print(lilfoo.bar)
print(lilfoo.baaz)
Как получить строковое представление переменной в python?