2024-04-26 18:19:27 发布
网友
我用它来判断现在的截图是否和上次截图不同。 现在我用
with open('last_screenshot.bmp','rb+') as f: org = f.read() with open('now_screenshot.bmp','rb+') as f: new = f.read() if(org==new): print("The pictures are same")
有没有更快的方法
比较像素是行不通的。您的选择:
您可以使用标准库附带的^{}。这不会将整个文件读入内存,而是在遇到不同的块时read them in chunks和短路。用法示例:
import filecmp if filecmp('last_screenshot.bmp', 'now_screenshot.bmp', shallow=False): print('Files compare equal')
你可以一块一块地迭代文件,而不是在内存中读取整个内容
或者,使用filecmp或shell out来cmp(1)
比较像素是行不通的。您的选择:
您可以使用标准库附带的^{} 。这不会将整个文件读入内存,而是在遇到不同的块时read them in chunks和短路。用法示例:
你可以一块一块地迭代文件,而不是在内存中读取整个内容
或者,使用filecmp或shell out来cmp(1)
相关问题 更多 >
编程相关推荐