How to get the value of a specific attribute from a specific object in Python

2 Answers

0 votes
class Worker:
    name = "Fox"
    age = 52
    profession = "Programmer"

x = getattr(Worker, 'profession')

print(x)


'''
run:

Programmer

'''

 



answered Dec 11, 2018 by avibootz
0 votes
class Worker:
    name = "Fox"
    age = 52
    profession = "Programmer"

x = getattr(Worker, 'salary', "salary not exist")

print(x)


'''
run:

salary not exist

'''

 



answered Dec 11, 2018 by avibootz
...