-2

I am trying to convert a string input as part of variable.

Ex :

lets say input string is A

Api.setting = Setting.SetA

if input string is 1

Api.setting = Setting.Set1

I have implemented with all possible cases like

if input1 == "A":
    Api.setting = Setting.SetA
elif input1 == "1":
    Api.setting = Setting.Set1

etc;

I am unsure if I have covered all possible cases or not. And also if new cases come, I need to add new elif conditions.

Is there a better way to do it?

Jamie
  • 1
  • 4
  • `input` is the built-in function. Do not use it as a variable name. Everything else in your post is completely unclear. What are `Setting.SetA` and `Setting.Set1`? – DYZ May 09 '22 at 07:29
  • Setting.SetA and Sett.ingSet1 are API imported from a dll. We are assigning the values according to the input. – Jamie May 10 '22 at 03:24
  • Does this answer your question? [Python: access class property from string](https://stackoverflow.com/questions/1167398/python-access-class-property-from-string) – Pranav Hosangadi May 10 '22 at 03:38

1 Answers1

-2

I think you call directly with the input variable

Example:

Api.setting = Setting.Set + str(input)
Sheshananda Naidu
  • 905
  • 1
  • 9
  • 10