我正尝试在pi上搜索一组特定的数字,并使其返回起始和结束索引位置。该代码可以很好地处理100万位数的pi,但是一旦尝试10亿位数,我就会遇到内存错误(1B为953mb)。
import re
search_inp = raw_input("What do you want to find?: ")
with open("1B_Pi.txt") as infile:
for line in infile:
string = str(line)
a = re.search(search_inp, string)
else:
print (a.start()),(a.start())+len(search_inp)
print (line[(a.start()):((a.start())+len(search_inp))])
输出:infile中的行:MemoryError