-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

0

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,441
  • 1
  • 14
  • 23
0

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
  • 9,296
  • 16
  • 43
  • 89