Answer the question
In order to leave comments, you need to log in
How to write characters to a file?
Hello, I'm trying to make it so that after pressing a key it is immediately written to a text file
. I tried this:
import keyboard
x = open('test.txt','a')
def print_pressed_keys(e):
x.write(str( e.name))
print(e.name)
keyboard.hook(print_pressed_keys)
keyboard.wait()
The file remains empty, but the press passes and print prints it out. Tell me what to do.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question