我需要帮助...我已经在python中编写代码来确定集合基础的所有组合...但是,输出文件很大,具体取决于基础的长度
是否可以添加代码,使其能够以5gbs的块创建输出文件,然后可以从总输出中删除但仍允许程序在中断的地方继续?这是我最关心的问题......我不确定如何在不失去已经产生的情况下如何处理这个问题,但我担心这可能不太可行......任何建议都会非常感激......谢谢。
温迪
当前代码:
import itertools
BASE = "stayreadytokeepfromgettingready"
REPEAT = 4
def repetitions_for_letter(letter):
return [letter * count for count in range(1, REPEAT + 1)]
def repetitions_for_word(word):
return [repetitions_for_letter(letter) for letter in word]
def generate(word):
length = len(word)
repetitions = repetitions_for_word(word)
file_object = open('possibilities.txt', 'w')
print("Begining generation...")
for pick_indexes in itertools.product(range(REPEAT),repeat=length):
parts = [repetitions[idx][pick] for idx, pick in
enumerate(pick_indexes)]
file_object.write("".join(parts) + "\n")
file_object.close()
print("Finished...")
generate(BASE)