我正在重构一个可怕的python脚本,它是生成lua绑定的polycode项目的一部分。你知道吗
我正在考虑将lua行写出来,因为它们是以块的形式生成的。你知道吗
但我的一般问题是,快速写入文件有什么坏处/注意事项?
举个例子:
persistent_file = open('/tmp/demo.txt')
for i in range(1000000):
persistent_file.write(str(i)*80 + '\n')
for i in range(2000):
persistent_file.write(str(i)*20 + '\n')
for i in range(1000000):
persistent_file.write(str(i)*100 + '\n')
persistent_file.close()
这只是一种简单的方法,基本上是以最快的速度写入文件。 我真的不希望碰到任何真正的问题这样做,但我想知道,这是有利于缓存一个大写?你知道吗
从
open
函数的文档中:换句话说,在大多数情况下,您在频繁调用
write()
时遇到的唯一开销是函数调用的开销。你知道吗相关问题 更多 >
编程相关推荐