python - Save ascii as clear string into txt file -
my code:
f = open("log.txt", "a") key = chr(event.ascii) f.write(key) f.closed
if print key out. nice readable form "a" "b" "c" , on. if file python has saved ascii - that: 0013 0200 4461
i tried convert errors. knows whats wrong here?
i think need f.close()
not f.closed
.
also, putting key code in key.
if want read single char, use:
sys.stdin.read(1)
(see: https://stackoverflow.com/a/510404/103081)
putting together:
import sys f = open("log.txt", "a") key = sys.stdin.read(1) f.write(key) f.close()
this should fine homework problem or learning python on own. writing keylogger steal password , credit card numbers, though, useless because return must hit input.
Comments
Post a Comment