-1
DS1 = 89.3923
Label = "DS1"
LabelValue = Label
print(LabelValue)

I'm stuck on something, I have some calculations which determines the value for "Label" in the case above, it's DS1. I want to return the actual value contained in DS1 when printing LabelValue so the print should result in 89.3923 rather than DS1.

1 Answers1

0

First this is generally a bad idea and you should instead use a dictionary like this:

d = {"DS1": 89.3923}
Label = d["DS1"]
LabelValue = Label
print(LabelValue)

But if you really don't want to you can look it up in locals.

DS1 = 89.3923
Label = locals()["DS1"]
LabelValue = Label
print(LabelValue)
RedKnite
  • 1,525
  • 13
  • 26