[Tutor] Fastest way to iterate through a file
elis aeris
hunter92383 at gmail.com
Sun Jul 1 23:12:18 CEST 2007
I found out that by making a copy of it, it can be load() ed !
it runs 3 times faster now
import time
import ImageGrab
from ctypes import *
class RECT(Structure):
_fields_ = [
('left', c_ulong),
('top', c_ulong),
('right', c_ulong),
('bottom', c_ulong)
]
GetForegroundWindow = windll.user32.GetForegroundWindow
GetWindowRect = windll.user32.GetWindowRect
rect = RECT()
foreground_window = GetForegroundWindow()
GetWindowRect(foreground_window, byref(rect))
image = ImageGrab.grab((rect.left, rect.top, rect.right, rect.bottom))
start_time = time.time()
num_pixels = 0
num_black = 0
pix = image.copy().load()
print time.time()
for x in xrange(200):
for y in xrange(200):
num_pixels += 1
if pix[x, y] == (0, 0, 0):
num_black += 1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070701/4d1e738d/attachment.html
More information about the Tutor
mailing list