1

I am using Python pywinauto to let the program automatically enter new line 20 times. I don't want to put 20 directly in send_keys() like: send_keys('{ENTER 20}').

Instead, I want to pass an assignment of repetition count (ie: n=20) to send_keys(), like send_keys('{ENTER n}'). The whole program is:

from pywinauto.keyboard import send_keys
n=20
send_keys('{ENTER n}') -> This code not worked yet, still error here

Is there any solution for this? or how to pass argument by assignment to brackets inside the send_keys() in Python pywinauto?

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
Thy Khuu
  • 13
  • 3

2 Answers2

0

It's a general Python question not specific to pywinauto. For example, this way:

send_keys(f'{{ENTER {n}}}')

F-string requires un-escaping { or } by doubling it: https://stackoverflow.com/a/5466478/3648361

It's easy to check in any IDE with interactive interpreter:

>>> f'{{ENTER {n}}}'
'{ENTER 20}'
Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
0

You can use f-strings. See here

from pywinauto.keyboard import send_keys
n=20
send_keys(f'{{ENTER {n}}}')
cup11
  • 177
  • 7