0

I have a string A:

import keyboard

A = "keyboard.press_and_release('left windows+R')"

But, I want it to work as a function. If I call A, then it should press Windows Key and R key present on y keyboard.

2 Answers2

1

You can use eval:

a = "keyboard.press_and_release('left windows+R')"
eval(a)
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

Try using eval. See https://docs.python.org/3.6/library/functions.html#eval or What does Python's eval() do?

import keyboard

A = "keyboard.press_and_release('left windows+R')"
eval(A)
JDong
  • 2,304
  • 3
  • 24
  • 42