-3

How to implement a search item in the worksheet with the properties of the subsequent withdrawal?

O213YB = '1111  2222'
    B443TH = '3333  4444'
    DATA = ['O211YB','B896PM','B897PM','O209YB','X899HK','B805TH','A758KP']
    nomer = input('input name ->')
if nomer in DATA:

2 Answers2

-1

Okay, so from your comments I figured out what you want the program to do.

You could get the value using the global variable as follows:

if nomer in DATA:
    print(globals()[nomer])

For more info on that, see this post.

However, I would strongly recommend you restructure your data to a dict. Your code would then look like this:

data = {
    'O211YB': '1111 2222',
    'B896PM': '3333 4444',
    # Etcetera
}
if nomer in data.keys():
    print( data[nomer] )
Community
  • 1
  • 1
Jorick Spitzen
  • 1,559
  • 1
  • 13
  • 25
-1

So what I understood from your comments that what you want is get values of each variable referenced by its name as a string in DATA ..

In that case all you need is eval():

for x in DATA:
    print eval(x)
farhawa
  • 10,120
  • 16
  • 49
  • 91
  • [**Do not ever use `eval` (or `exec`) on data that could possibly come from outside the program in any form. It is a critical security risk. You allow the author of the data to run arbitrary code on your computer.**](https://stackoverflow.com/questions/1832940/why-is-using-eval-a-bad-practice) – Karl Knechtel Jul 05 '22 at 02:02