Alternatives to using eval()

Hi, I’m new to python, so this might be a simple problem, but i couldn’t find answer by searching. I want a function to return keyboard input for any given key. I couldn’t add argument into code, so i added it to string. But because eval() is a potential security risk, i would prefer not using it. Is there a better way to get the same result?:o

import bge

def button(key):
    return eval('[' + key + ']')

if (button('WKEY')) == 1:
if (button('SKEY')) == 1:
if (button('AKEY')) == 1:
if (button('DKEY')) == 1:

Try this:

def button(key):
    return[getattr(, key)]

Thanks! :slight_smile:
getattr() does exactly what i needed.