0

Let's say that I have a class:

class Hello():
    who = {they, you}
    how = {good, bad}

And with a function parameter I want to specify which attribute I want to see.

def choose(who_or_how):
    print(Hello.who_or_how) 

Is there a way for doing it?

Lorenzo
  • 15
  • 2
  • You could use e.g. `getattr(Hello, 'who')`. But that is sometimes a code smell - instead it may be better to put `who` and `how` into a `dict`. – 0x5453 Jun 24 '22 at 12:36
  • Does this answer your question? https://stackoverflow.com/questions/2612610/how-to-access-object-attribute-given-string-corresponding-to-name-of-that-attrib – Iain Shelvington Jun 24 '22 at 12:37

0 Answers0