Python / IDLE CPU 无故使用
这是我在 Windows 上使用 IDLE(版本 2.6.5,具有相同 Python 版本)时遇到的一个奇怪问题。
我尝试运行以下三个命令:
fid= open('file.txt', 'r')
lines=fid.readlines()
print lines
当执行 printlines 命令时,pythonw.exe 进程的 CPU 疯狂,消耗 100% 的 CPU,并且 IDLE 似乎没有响应。 file.txt 大约 130 kb - 我不认为该文件很大!
当这些行最终打印出来时(几分钟后),如果我尝试向上滚动查看它们,我会再次遇到同样非常大的 CPU 使用率。
pythonw.exe 的内存使用量始终在 15-16 MB 左右。
任何人都可以向我解释这种行为 - 显然这不可能是 IDLE 中的错误,因为它会被发现......另外,我能做些什么来抑制这种行为?我喜欢使用 IDLE 来执行类似涉及文件数据转换的脚本任务。
Here is a strange problem I have with IDLE (version 2.6.5 with the same Python version) on windows.
I try to run the following three commands:
fid= open('file.txt', 'r')
lines=fid.readlines()
print lines
When the print lines command is executed, the pythonw.exe process is going CPU crazy, consuming 100% of CPU and the IDLE seems to not be responding. The file.txt is around 130 kb - I don't consider that file very large !
When the lines finally print (after some minutes), if I try to scroll up to see them, I once again experience the same very large CPU usage.
The memory usage of pythonw.exe is around 15-16 MB all the time.
Can anybody explain to me this behaviour - obviously this can't be a bug in IDLE since it would have been discovered ... Also, what can I do to supress that behavior ? I like using IDLE for script like tasks involving data transformations from files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试逐行阅读:
来自 输入输出,读取文件的方式好像有两种:
Try reading it line by line:
From the documentation on Input Output, there seem to be two ways to read files: