在我的小程序中,我使用
file = open("txtfile.txt", "w")
file.write(my_string)
file.close
字符串实际上是一个列表,只是使用str(my_list)转换为str,当我打开文件时出现问题。它起初看起来很好但是如果你走到最后,你会发现有一些值缺失,包括关闭列表的括号。这是可测试的代码:
import ast
### dont worry about the function
def p5map(n, start1, stop1, start2, stop2):
return ((float(n)-start1)/(stop1-start1))*(stop2-start2)+start2
### what is inside the txt file will be at the end, just copy and paste it
### in a txt file named "best_DNA"
with open("best_DNA.txt", "r") as f:
pop = ast.literal_eval(f.readline().rstrip())
### this is just to convert what is in the txt file into what I want
maxLenPerState = 16*3+1
maxState = 36
newInput = [[] for _ in xrange(len(pop))]
temp = [0 for _ in xrange(maxState*maxLenPerState)]
for cube in xrange(len(pop)):
newInput[cube] = temp
for state in xrange(len(pop[cube])):
newInput[cube][state*maxLenPerState] = p5map(state, 0, maxState-1, 0, 1)
### if you actually print the newInput, you will see that at the end of it,
### there is the closing bracket
print newInput
### here is where I write into the file, **MAKE SURE YOU HAVE NO IMPORTANT TXT
### FILE NAMED "test0" !!!!!!!!**
mystr = str(newInput)
#print mystr #you can even print the string version of "newInput" and the closing bracker are here
file = open("test0.txt", "w")
file.write(mystr)
file.close
现在,如果你打开test0.txt,你会发现有一个关闭括号丢失,也有一些值,为什么会这样?
你的“best_DNA”txt文件应该包含哪些内容:
[[[(0, 0, -1, -1), (1, 0, 0.0625), (-1, 0, 3.0625), (1, 1, 9.0625), (1, 0, -4.9375), (-1, 1, -5.9375), (-1, -1, -4.9375), (-1, -1, 1.0625), (0, 0, -0.9375), (-1, -1, -0.9375), (1, 1, -1.9375), (0, -1, 8.0625), (0, -1, 5.0625), (0, -1, 7.0625), (1, 1, -2.9375), (-1, 0, 4.0625), (1, -1, 5.0625)], [(0, 0, -1, 0), (0, 0, 1.3125), (-1, 1, 0.3125), (0, 1, 6.3125), (-1, -1, -0.6875), (1, 0, 6.3125), (0, -1, -5.6875), (1, -1, -0.6875), (1, -1, 3.3125), (0, 0, 1.3125), (0, -1, -6.6875), (1, 0, 2.3125), (-1, 0, 3.3125), (0, -1, -6.6875), (1, 0, 8.3125), (1, 1, -0.6875), (0, 1, 8.3125)], [(0, 0, -1, 1), (-1, 1, 0.6875), (1, 1, -4.3125), (0, 0, -0.3125), (-1, 0, 9.6875), (0, 0, 0.6875), (1, 0, 0.6875), (-1, 1, 8.6875), (-1, -1, -2.3125), (0, 0, 1.6875), (-1, 0, -3.3125), (-1, 1, 1.6875), (1, -1, 5.6875), (1, -1, 7.6875), (0, 0, -5.3125), (-1, -1, 2.6875), (-1, -1, -4.3125)], [(0, 0, 0, -1), (0, 0, 3.125), (0, 1, 0.125), (1, -1, -1.875), (-1, -1, -7.875), (0, -1, 6.125), (1, 0, 1.125), (-1, 0, -3.875), (1, 0, 5.125), (1, -1, 1.125), (1, 1, 5.125), (0, 0, -1.875), (1, 1, 4.125), (0, -1, 4.125), (1, 0, -4.875), (0, 1, 7.125), (-1, 1, 3.125)], [(0, 0, 0, 0), (0, -1, 0.3125), (1, -1, 6.3125), (-1, -1, -6.6875), (1, 0, 7.3125), (-1, -1, -6.6875), (0, -1, -3.6875), (-1, 0, 6.3125), (0, 1, 1.3125), (1, 0, 7.3125), (1, 1, -6.6875), (1, -1, -4.6875), (0, 0, 5.3125), (0, 1, -4.6875), (1, 0, 6.3125), (-1, 1, 6.3125), (1, -1, 6.3125)], [(0, 0, 0, 1), (0, -1, 9.6875), (-1, -1, 6.6875), (0, 0, -0.3125), (-1, 1, -5.3125), (-1, 0, -4.3125), (0, -1, 7.6875), (0, 0, 0.6875), (-1, 0, -3.3125), (1, 1, 7.6875), (1, 0, 4.6875), (-1, -1, -5.3125), (-1, -1, 0.6875), (1, -1, 2.6875), (-1, -1, -3.3125), (1, -1, -0.3125), (0, 1, 1.6875)], [(0, 0, 1, -1), (-1, 0, 4.1875), (-1, 1, 0.1875), (-1, 0, -1.8125), (-1, 0, 2.1875), (1, -1, 4.1875), (0, 0, -5.8125), (1, 1, 7.1875), (0, 0, 7.1875), (0, 0, -6.8125), (1, 0, -2.8125), (1, 0, 1.1875), (-1, 1, 7.1875), (1, 1, 7.1875), (0, 1, 2.1875), (1, 1, 0.1875), (0, 0, -5.8125)], [(0, 0, 1, 0), (0, 1, -6.6875), (0, 0, -3.6875), (-1, 0, -2.6875), (0, -1, 8.3125), (-1, 0, 2.3125), (1, -1, 3.3125), (0, 0, 1.3125), (0, 0, 4.3125), (1, -1, 8.3125), (-1, 0, 0.3125), (-1, -1, -5.6875), (1, 0, 6.3125), (1, -1, 5.3125), (1, 1, 8.3125), (0, 1, -6.6875), (0, -1, -2.6875)], [(0, 0, 1, 1), (0, 0, 1.0), (-1, 1, 7.0), (0, -1, -1.0), (1, -1, 3.0), (1, 1, 1.0), (1, 0, -1.0), (1, 0, 2.0), (1, 1, -3.0), (-1, 1, 1.0), (-1, 1, -2.0), (0, -1, -4.0), (1, -1, -2.0), (1, -1, -1.0), (0, 1, 1.0), (1, 1, 7.0), (-1, -1, 11.0)], [(0, 1, -1, -1), (0, 0, -2.375), (1, 1, 5.625), (-1, 1, 1.625), (-1, 1, -4.375), (-1, -1, -1.375), (1, 0, 5.625), (0, 1, -3.375), (0, -1, 8.625), (0, 0, -2.375), (-1, -1, 7.625), (1, 1, 8.625), (0, 1, -4.375), (-1, 1, -1.375), (0, 1, 4.625), (0, 0, -1.375), (-1, 1, -1.375)], [(0, 1, -1, 0), (-1, 0, 4.375), (-1, 1, -3.625), (1, 0, -3.625), (1, 1, 7.375), (1, -1, 0.375), (0, 0, 1.375), (-1, 1, 5.375), (1, 1, -0.625), (0, -1, -4.625), (0, 0, 0.375), (0, -1, -0.625), (-1, 1, 7.375), (-1, -1, 0.375), (-1, 0, 1.375), (-1, 0, 5.375), (0, 0, -0.625)], [(0, 1, -1, 1), (0, 1, 7.3125), (0, 0, 2.3125), (0, 0, 6.3125), (0, 1, -3.6875), (1, 0, 3.3125), (0, -1, -3.6875), (1, 1, -0.6875), (1, -1, 0.3125), (1, 1, 7.3125), (0, 1, -1.6875), (0, 0, 4.3125), (-1, 0, 3.3125), (-1, 1, -1.6875), (1, 0, -5.6875), (1, -1, -3.6875), (-1, -1, 6.3125)], [(0, 1, 0, -1), (-1, 0, -3.0625), (-1, 1, 3.9375), (-1, 1, 1.9375), (-1, -1, 2.9375), (0, 0, 5.9375), (0, -1, -2.0625), (-1, -1, -1.0625), (-1, 0, -7.0625), (1, 0, 2.9375), (-1, 1, -2.0625), (-1, 0, 0.9375), (1, -1, 2.9375), (1, 0, 6.9375), (1, -1, -2.0625), (1, 1, 1.9375), (1, -1, 6.9375)], [(0, 1, 0, 0), (1, 0, -2.75), (-1, 0, 8.25), (1, 1, 8.25), (-1, -1, 0.25), (1, -1, -3.75), (-1, -1, 7.25), (-1, 1, 2.25), (0, 0, 8.25), (0, 1, -5.75), (1, 0, -3.75), (-1, -1, 8.25), (-1, 1, -5.75), (-1, 0, 2.25), (1, -1, -1.75), (0, 0, 3.25), (-1, 0, -4.75)], [(0, 1, 0, 1), (0, 0, -1.0), (-1, -1, 1.0), (-1, -1, 5.0), (-1, -1, -6.0), (-1, 1, 4.0), (-1, 1, 2.0), (0, -1, 5.0), (-1, 1, 1.0), (0, 1, 0.0), (1, 1, -6.0), (0, 1, -1.0), (1, 1, -1.0), (-1, 1, 8.0), (0, -1, 4.0), (1, 0, 0.0), (-1, 0, 5.0)], [(0, 1, 1, -1), (-1, -1, -3.0625), (1, 0, -3.0625), (-1, 1, -0.0625), (-1, 1, 1.9375), (1, 0, 8.9375), (1, -1, 6.9375), (0, 1, 5.9375), (1, 1, 0.9375), (-1, -1, 7.9375), (-1, 1, -3.0625), (-1, -1, -1.0625), (-1, -1, -1.0625), (-1, -1, -2.0625), (1, -1, 6.9375), (-1, 0, -3.0625), (1, 1, -3.0625)], [(0, 1, 1, 0), (-1, -1, 6.25), (-1, -1, 7.25), (0, -1, 4.25), (1, 1, 7.25), (1, 0, -1.75), (-1, 0, -4.75), (1, 0, -4.75), (1, 1, 2.25), (1, 1, -4.75), (1, -1, 5.25), (1, 1, -5.75), (1, -1, 8.25), (1, 0, 6.25), (1, -1, -4.75), (-1, 0, -1.75), (0, 1, 1.25)], [(0, 1, 1, 1), (0, 1, -3.3125), (-1, -1, 0.6875), (1, 0, 2.6875), (1, 0, -2.3125), (1, -1, -4.3125), (-1, -1, -5.3125), (1, -1, 7.6875), (1, -1, 6.6875), (1, -1, 3.6875), (-1, -1, 6.6875), (1, 1, -2.3125), (-1, 1, 4.6875), (-1, 0, 2.6875), (1, 1, -6.3125), (1, -1, 5.6875), (-1, 1, 2.6875)], [(1, 0, -1, -1), (1, -1, -1.0), (1, -1, 8.0), (0, 0, 1.0), (0, 1, 1.0), (0, 0, -2.0), (0, 1, -3.0), (-1, -1, 3.0), (1, 0, -6.0), (1, -1, -2.0), (1, 0, 4.0), (-1, 1, 7.0), (-1, 1, 8.0), (0, -1, -6.0), (-1, -1, 4.0), (0, -1, 6.0), (1, 1, -2.0)], [(1, 0, -1, 0), (-1, 0, 6.4375), (0, 0, 8.4375), (-1, 1, -2.5625), (-1, 0, 1.4375), (1, 1, -2.5625), (-1, 0, 5.4375), (1, 0, 7.4375), (1, 0, -6.5625), (0, 0, 3.4375), (0, 0, -4.5625), (1, 0, -5.5625), (1, 0, 3.4375), (0, -1, 0.4375), (-1, 0, -6.5625), (-1, -1, 7.4375), (1, 0, 4.4375)], [(1, 0, -1, 1), (-1, -1, -7.1875), (1, -1, 5.8125), (1, -1, 4.8125), (0, 0, -0.1875), (1, 1, 6.8125), (0, 1, 3.8125), (-1, -1, -4.1875), (0, 1, 3.8125), (1, 0, -8.1875), (0, -1, 1.8125), (1, -1, -0.1875), (1, -1, -2.1875), (-1, 0, 1.8125), (-1, 1, 6.8125), (1, -1, 1.8125), (-1, -1, 4.8125)], [(1, 0, 0, -1), (-1, -1, 5.8125), (-1, -1, -3.1875), (0, 0, 3.8125), (0, 0, -2.1875), (1, -1, 6.8125), (-1, 1, 0.8125), (1, -1, 4.8125), (-1, -1, 3.8125), (-1, 1, -4.1875), (0, 0, -1.1875), (0, -1, -0.1875), (-1, -1, 8.8125), (-1, 1, -4.1875), (-1, 0, 2.8125), (1, 0, -5.1875), (0, 0, 2.8125)], [(1, 0, 0, 0), (-1, 1, -0.8125), (1, 1, 3.1875), (1, 0, -5.8125), (0, 0, -2.8125), (0, 0, 1.1875), (1, 0, 7.1875), (1, -1, 2.1875), (1, -1, 5.1875), (0, -1, 6.1875), (1, 0, 3.1875), (0, 1, -0.8125), (0, -1, -4.8125), (-1, 0, 5.1875), (0, -1, 2.1875), (1, 0, 3.1875), (1, 0, -3.8125)], [(1, 0, 0, 1), (0, 1, 2.125), (0, 1, 6.125), (0, -1, 3.125), (-1, -1, 4.125), (0, -1, -5.875), (1, 1, 1.125), (0, 1, 5.125), (1, 0, -2.875), (0, -1, -3.875), (-1, 1, -1.875), (1, 0, 9.125), (-1, 1, -1.875), (-1, 1, -2.875), (-1, 0, 3.125), (1, 0, -3.875), (1, -1, 9.125)], [(1, 0, 1, -1), (-1, -1, -2.125), (1, 1, 5.875), (-1, 1, -5.125), (0, 1, 3.875), (0, 0, 3.875), (1, -1, 6.875), (-1, 1, 3.875), (1, -1, 4.875), (0, -1, 4.875), (0, 0, 1.875), (-1, -1, -3.125), (1, -1, 4.875), (1, 0, -7.125), (1, -1, 6.875), (0, 1, -7.125), (-1, 0, -3.125)], [(1, 0, 1, 0), (0, -1, 1.0625), (1, -1, -3.9375), (0, 0, 3.0625), (-1, 1, 2.0625), (-1, -1, 7.0625), (0, -1, 1.0625), (1, 1, -0.9375), (1, 1, -4.9375), (1, 0, 6.0625), (-1, 1, 9.0625), (1, 0, -4.9375), (1, 1, -1.9375), (1, 1, -0.9375), (-1, 1, 8.0625), (0, -1, -4.9375), (0, 0, 5.0625)], [(1, 0, 1, 1), (-1, 1, -5.5625), (1, 1, -6.5625), (-1, 1, -5.5625), (1, 0, 6.4375), (0, 0, -1.5625), (1, 0, 7.4375), (1, 1, 8.4375), (-1, 0, 2.4375), (0, 1, 1.4375), (-1, 0, 8.4375), (0, 1, 0.4375), (-1, -1, -2.5625), (-1, -1, -4.5625), (-1, 1, 8.4375), (-1, 1, 5.4375), (-1, 0, -2.5625)], [(1, 1, -1, -1), (1, -1, 2.9375), (-1, -1, 1.9375), (1, -1, 5.9375), (-1, 1, -0.0625), (-1, 1, -3.0625), (-1, -1, 6.9375), (1, 0, -3.0625), (0, -1, 9.9375), (0, 1, 2.9375), (0, 0, -5.0625), (-1, -1, -4.0625), (0, -1, 7.9375), (1, -1, -5.0625), (1, -1, 0.9375), (0, 0, 3.9375), (1, 0, -3.0625)], [(1, 1, -1, 0), (1, 0, -6.1875), (0, 0, 4.8125), (0, 1, -1.1875), (0, -1, 4.8125), (1, 1, 5.8125), (1, -1, 6.8125), (1, 1, 1.8125), (1, 0, 2.8125), (-1, 0, -1.1875), (-1, -1, -4.1875), (-1, 0, 6.8125), (0, 1, 5.8125), (1, 1, -8.1875), (-1, -1, -4.1875), (0, 0, 6.8125), (-1, 0, -1.1875)], [(1, 1, -1, 1), (-1, 0, 2.375), (0, 0, -4.625), (-1, 1, -5.625), (-1, 0, 0.375), (-1, 1, 8.375), (-1, 1, 6.375), (0, -1, 4.375), (0, 1, -0.625), (1, -1, 7.375), (0, -1, 7.375), (1, 1, 1.375), (-1, -1, -1.625), (1, 0, -4.625), (-1, 0, 5.375), (-1, 1, -0.625), (-1, 1, -5.625)], [(1, 1, 0, -1), (-1, 1, -4.75), (-1, 0, 2.25), (0, 0, 5.25), (1, 0, -4.75), (-1, -1, 1.25), (-1, 0, 2.25), (0, 1, -0.75), (0, 0, -4.75), (1, -1, 6.25), (-1, 1, -3.75), (-1, 0, 8.25), (0, -1, -1.75), (-1, 1, 6.25), (-1, 1, 6.25), (0, 0, 3.25), (0, 0, -0.75)], [(1, 1, 0, 0), (0, 0, 5.5), (-1, 0, -5.5), (0, -1, 7.5), (0, -1, -4.5), (-1, -1, 4.5), (1, 0, -4.5), (0, -1, 7.5), (-1, 0, -3.5), (0, 0, -2.5), (0, 1, 0.5), (0, -1, -0.5), (-1, 1, -0.5), (0, 1, -2.5), (0, 1, 7.5), (0, 0, 5.5), (0, 0, 5.5)], [(1, 1, 0, 1), (0, 1, 1.0625), (0, -1, -1.9375), (0, 1, 8.0625), (1, -1, 5.0625), (-1, 1, -4.9375), (-1, -1, 9.0625), (0, 1, -3.9375), (-1, -1, -4.9375), (0, 1, -4.9375), (-1, -1, 0.0625), (1, -1, 5.0625), (0, -1, -4.9375), (1, 0, 2.0625), (-1, -1, 10.0625), (0, 1, 9.0625), (1, 0, -3.9375)], [(1, 1, 1, -1), (1, -1, 0.375), (1, 0, 1.375), (0, -1, 10.375), (0, 0, 4.375), (-1, -1, -2.625), (1, 0, 8.375), (0, -1, -2.625), (-1, 0, -4.625), (-1, 1, 7.375), (-1, 1, 6.375), (0, 0, -4.625), (0, 0, 6.375), (-1, 0, -4.625), (0, 1, -0.625), (-1, 0, -4.625), (0, 1, -0.625)], [(1, 1, 1, 0), (0, 0, 0.125), (0, 0, 1.125), (1, 0, 1.125), (-1, 1, -5.875), (1, 0, 1.125), (1, 0, 8.125), (-1, -1, -3.875), (0, 1, 1.125), (-1, 1, 5.125), (-1, 1, -2.875), (1, 1, 4.125), (0, 1, -1.875), (1, -1, -0.875), (0, 1, 7.125), (1, 0, 0.125), (-1, 0, 6.125)], [(1, 1, 1, 1), (0, -1, -5.375), (-1, 0, -2.375), (1, 1, -4.375), (-1, 0, -2.375), (1, 0, 5.625), (0, -1, -1.375), (1, -1, -0.375), (0, 0, 3.625), (0, 0, 2.625), (0, 0, 1.625), (-1, 1, 7.625), (0, 1, 6.625), (1, 0, 7.625), (0, 1, -6.375), (-1, 1, 4.625), (1, 0, 2.625)]], [[(0, 0, -1, -1), (-1, -1, 5.9375), (0, -1, 2.9375), (0, -1, -4.0625), (-1, -1, 0.9375), (0, -1, -0.0625), (0, 0, 2.9375), (-1, -1, -1.0625), (1, 0, -3.0625), (1, 0, 0.9375), (1, 0, -2.0625), (-1, 0, 3.9375), (0, 1, 9.9375), (0, 0, -2.0625), (1, 0, 2.9375), (-1, 0, -2.0625), (0, 1, 3.9375)], [(0, 0, -1, 0), (1, 1, 9.6875), (-1, 0, 9.6875), (-1, 0, -3.3125), (-1, -1, 2.6875), (0, -1, -4.3125), (-1, 1, 6.6875), (0, 1, -4.3125), (-1, -1, -4.3125), (1, 1, 1.6875), (-1, 1, -3.3125), (1, 0, 0.6875), (1, 0, -3.3125), (0, 1, 10.6875), (-1, 1, -3.3125), (1, 0, 8.6875), (-1, -1, -4.3125)], [(0, 0, -1, 1), (-1, 0, 7.25), (1, -1, -5.75), (0, -1, 8.25), (-1, 0, 1.25), (0, -1, 4.25), (-1, 1, 3.25), (-1, 1, 7.25), (1, -1, -4.75), (0, 0, -4.75), (-1, -1, -3.75), (0, -1, 0.25), (1, 1, 5.25), (0, 0, 8.25), (0, 0, -4.75), (1, 0, 4.25), (0, -1, -5.75)], [(0, 0, 0, -1), (-1, 1, 6.4375), (-1, 1, -6.5625), (1, -1, -8.5625), (1, 0, 5.4375), (-1, -1, 6.4375), (-1, 1, 2.4375), (1, -1, 0.4375), (0, 0, 3.4375), (0, 1, -2.5625), (1, 1, 0.4375), (1, 1, -4.5625), (-1, 0, 5.4375), (0, 0, 6.4375), (-1, -1, 0.4375), (-1, 0, 3.4375), (1, 1, 1.4375)], [(0, 0, 0, 0), (-1, 0, 8.375), (-1, 1, -3.625), (0, 1, -4.625), (-1, 1, -4.625), (0, -1, -1.625), (-1, 0, 8.375), (-1, 1, 5.375), (-1, 1, -3.625), (1, 0, -2.625), (0, -1, 2.375), (1, -1, 6.375), (1, 0, 4.375), (-1, 1, -1.625), (-1, 1, 6.375), (0, 0, -3.625), (0, -1, 4.375)], [(0, 0, 0, 1), (0, -1, 6.0625), (1, -1, -3.9375), (1, -1, 5.0625), (0, -1, 8.0625), (1, -1, 0.0625), (0, 0, -0.9375), (-1, -1, 0.0625), (0, 0, -3.9375), (1, 0, 1.0625), (1, 0, 2.0625), (-1, 0, 1.0625), (-1, -1, -3.9375), (-1, 0, 9.0625), (0, 0, 3.0625), (1, 1, -1.9375), (-1, -1, -0.9375)], [(0, 0, 1, -1), (1, 1, 0.375), (0, 1, 1.375), (-1, 1, 1.375), (-1, 1, -2.625), (0, 0, -1.625), (1, -1, 8.375), (-1, 1, -3.625), (0, 1, 1.375), (-1, 0, 1.375), (-1, 1, 4.375), (1, -1, -1.625), (1, -1, 6.375), (1, 1, -0.625), (0, -1, 8.375), (0, 0, 1.375), (-1, 0, -4.625)], [(0, 0, 1, 0), (1, 0, -1.0625), (-1, 0, -1.0625), (0, -1, 0.9375), (-1, 1, -8.0625), (1, 1, 2.9375), (1, -1, 0.9375), (0, 1, -1.0625), (-1, -1, -0.0625), (1, 0, 1.9375), (-1, 0, 0.9375), (1, -1, 4.9375), (-1, 1, 3.9375), (0, 0, 4.9375), (-1, 1, 5.9375), (1, -1, -1.0625), (-1, 1, 4.9375)], [(0, 0, 1, 1), (-1, 1, -1.6875), (1, -1, 5.3125), (1, -1, -1.6875), (1, 1, 1.3125), (-1, -1, -2.6875), (0, 0, 11.3125), (0, 1, -2.6875), (-1, 1, -3.6875), (-1, 1, -0.6875), (0, -1, -2.6875), (-1, 0, 0.3125), (1, 0, 3.3125), (-1, -1, 4.3125), (1, 1, -0.6875), (0, 1, 5.3125), (-1, -1, 5.3125)], [(0, 1, -1, -1), (0, 0, -5.1875), (0, 1, 5.8125), (1, 1, 2.8125), (0, 1, -1.1875), (0, 0, 0.8125), (0, 0, -5.1875), (-1, 1, 3.8125), (-1, 1, 1.8125), (1, 1, 4.8125), (-1, 1, -1.1875), (-1, 1, -0.1875), (1, -1, -4.1875), (0, 0, 5.8125), (0, 1, 6.8125), (0, 1, 6.8125), (-1, 0, -2.1875)], [(0, 1, -1, 0), (0, 1, 0.25), (-1, 0, 3.25), (-1, 0, -4.75), (-1, 0, 1.25), (-1, 0, 6.25), (1, 0, 5.25), (-1, 0, -0.75), (0, 1, -5.75), (-1, 0, 4.25), (0, 0, -2.75), (0, -1, 7.25), (1, -1, -2.75), (1, 0, -1.75), (-1, 0, 7.25), (0, -1, -2.75), (0, 0, 6.25)], [(0, 1, -1, 1), (1, 0, 4.625), (1, -1, 3.625), (1, 1, 5.625), (1, 0, 8.625), (0, 1, 1.625), (-1, 0, -1.375), (-1, -1, -0.375), (1, -1, -6.375), (-1, 1, -6.375), (-1, -1, 2.625), (1, -1, 4.625), (-1, 0, -3.375), (1, 1, -0.375), (1, 0, -6.375), (-1, 0, 7.625), (0, 0, 5.625)], [(0, 1, 0, -1), (0, 1, 8.375), (-1, 1, 7.375), (1, 1, -3.625), (0, 1, 5.375), (1, -1, 7.375), (1, 0, -5.625), (-1, 0, -3.625), (0, 0, -1.625), (0, -1, -2.625), (1, 0, -1.625), (0, -1, 6.375), (0, -1, 2.375), (1, 1, -0.625), (-1, -1, -0.625), (1, -1, 3.375), (0, -1, -0.625)], [(0, 1, 0, 0), (-1, 0, 7.5625), (0, 1, -3.4375), (0, 1, 7.5625), (1, 1, 6.5625), (0, -1, 4.5625), (-1, 0, -1.4375), (0, 1, -5.4375), (0, 1, -2.4375), (1, 0, 3.5625), (-1, 0, 5.5625), (1, -1, 3.5625), (-1, 1, -2.4375), (1, 1, 8.5625), (-1, -1, -5.4375), (-1, 0, -3.4375), (1, 1, -3.4375)], [(0, 1, 0, 1), (-1, -1, 1.75), (1, 0, -2.25), (0, 1, -4.25), (-1, -1, -0.25), (-1, -1, -0.25), (1, 0, -2.25), (1, 0, 5.75), (0, 0, 6.75), (0, 0, 1.75), (-1, -1, 0.75), (0, 0, 9.75), (-1, 0, 0.75), (-1, 1, -5.25), (0, 1, -2.25), (-1, -1, 8.75), (0, 0, 0.75)], [(0, 1, 1, -1), (0, -1, 0.0), (1, 1, -5.0), (0, -1, 1.0), (1, -1, 1.0), (0, -1, 1.0), (-1, 1, 8.0), (0, -1, 7.0), (-1, 1, -1.0), (-1, 1, -4.0), (-1, -1, 9.0), (1, -1, 0.0), (1, 1, -3.0), (-1, 0, -2.0), (1, 1, 8.0), (-1, -1, -6.0), (-1, -1, 6.0)], [(0, 1, 1, 0), (1, 0, 2.4375), (1, 1, 4.4375), (1, 1, -6.5625), (-1, 0, 1.4375), (-1, 0, 3.4375), (1, 1, -3.5625), (1, 0, 0.4375), (0, 0, 5.4375), (-1, -1, -0.5625), (-1, 0, 2.4375), (0, 1, 4.4375), (-1, 1, -0.5625), (1, -1, -7.5625), (0, -1, 1.4375), (1, 1, 6.4375), (-1, 1, 6.4375)], [(0, 1, 1, 1), (-1, -1, 0.375), (1, 0, -0.625), (0, -1, -7.625), (-1, -1, -5.625), (0, 1, 7.375), (-1, 1, -3.625), (-1, 0, 3.375), (0, -1, 7.375), (0, -1, 2.375), (0, -1, 3.375), (0, 1, 0.375), (-1, 1, 4.375), (-1, 1, 2.375), (1, 1, 7.375), (0, 1, -7.625), (0, 0, 6.375)], [(1, 0, -1, -1), (0, 0, -4.5), (1, 1, 0.5), (1, 0, -0.5), (0, 0, 5.5), (0, -1, -4.5), (-1, 0, 4.5), (-1, 0, -5.5), (-1, 0, 5.5), (-1, 1, 2.5), (0, -1, 4.5), (-1, 0, 7.5), (-1, 0, -4.5), (-1, 0, 7.5), (1, 0, -3.5), (0, -1, -3.5), (1, 0, 8.5)], [(1, 0, -1, 0), (-1, -1, 3.0625), (0, 1, -3.9375), (1, 0, 0.0625), (1, -1, 5.0625), (0, 0, 0.0625), (1, 0, -3.9375), (0, 0, -2.9375), (0, -1, -2.9375), (0, 0, -4.9375), (-1, 0, 7.0625), (-1, 0, 0.0625), (-1, -1, 8.0625), (1, 1, 1.0625), (0, 0, 7.0625), (1, 0, 1.0625), (-1, -1, 6.0625)], [(1, 0, -1, 1), (1, 1, 8.5), (0, -1, 7.5), (1, -1, -3.5), (1, 0, -3.5), (-1, 1, 7.5), (1, 1, -2.5), (-1, 0, -0.5), (-1, 0, -3.5), (0, 1, -4.5), (1, 0, -1.5), (1, 1, 2.5), (1, -1, -3.5), (0, 1, 7.5), (1, -1, -0.5), (0, 0, 3.5), (0, 0, 6.5)], [(1, 0, 0, -1), (0, 0, 6.8125), (-1, 0, -1.1875), (0, -1, 3.8125), (0, -1, -0.1875), (0, 0, 4.8125), (-1, -1, -0.1875), (1, 0, -2.1875), (1, -1, -3.1875), (0, 0, 3.8125), (0, 0, 1.8125), (-1, -1, -1.1875), (0, -1, 0.8125), (1, 0, -4.1875), (1, -1, 6.8125), (-1, -1, -4.1875), (0, 0, 7.8125)], [(1, 0, 0, 0), (1, 0, 1.4375), (-1, -1, 4.4375), (0, 1, -2.5625), (1, 0, -1.5625), (-1, 0, 3.4375), (1, 0, 0.4375), (1, 0, -2.5625), (1, 1, -4.5625), (0, 0, -2.5625), (0, 1, 2.4375), (-1, -1, 6.4375), (0, -1, -5.5625), (1, -1, 3.4375), (1, -1, 6.4375), (-1, 0, 9.4375), (-1, 0, 1.4375)], [(1, 0, 0, 1), (-1, 0, -3.5625), (0, -1, 9.4375), (1, 1, -4.5625), (-1, 0, 6.4375), (0, 1, -5.5625), (-1, -1, -1.5625), (0, 0, -0.5625), (1, 1, -2.5625), (-1, 0, 9.4375), (1, 0, 0.4375), (1, 0, 1.4375), (1, -1, 4.4375), (1, 1, -5.5625), (0, -1, 5.4375), (1, 0, 6.4375), (-1, 1, 0.4375)], [(1, 0, 1, -1), (1, 1, -2.125), (-1, -1, -1.125), (-1, 1, 5.875), (0, 1, -2.125), (0, -1, -1.125), (-1, 0, -4.125), (-1, 0, 2.875), (-1, 0, -2.125), (-1, -1, 6.875), (-1, 1, 1.875), (1, 1, -4.125), (1, -1, 8.875), (1, 0, 10.875), (-1, -1, 4.875), (1, -1, -1.125), (0, 0, -4.125)], [(1, 0, 1, 0), (-1, 1, -6.75), (-1, 1, -6.75), (1, 0, -0.75), (0, 1, -2.75), (0, -1, 4.25), (1, -1, 8.25), (1, -1, -5.75), (-1, 1, 6.25), (-1, 0, -2.75), (-1, 1, 3.25), (1, -1, 8.25), (-1, 0, 7.25), (0, 0, 4.25), (-1, 0, 0.25), (1, 0, 6.25), (1, -1, -2.75)], [(1, 0, 1, 1), (-1, 0, -0.3125), (1, 0, 0.6875), (1, -1, -3.3125), (0, 1, 7.6875), (0, 1, 4.6875), (-1, -1, -2.3125), (-1, 1, 3.6875), (-1, 1, -4.3125), (0, 1, 7.6875), (1, -1, 7.6875), (1, 1, 0.6875), (-1, -1, 6.6875), (0, 0, -0.3125), (0, 0, -4.3125), (1, -1, 1.6875), (-1, -1, -6.3125)], [(1, 1, -1, -1), (1, -1, 2.3125), (0, 1, -0.6875), (1, -1, 8.3125), (1, -1, 2.3125), (1, 1, -4.6875), (-1, 1, 3.3125), (0, 0, 2.3125), (-1, -1, -5.6875), (1, 0, -3.6875), (0, 0, 7.3125), (-1, 1, 7.3125), (-1, 0, -0.6875), (1, 1, -5.6875), (0, 0, 1.3125), (0, 1, -2.6875), (-1, 1, 9.3125)], [(1, 1, -1, 0), (0, -1, 6.0), (-1, 0, 6.0), (1, -1, -3.0), (1, 0, 5.0), (0, 1, 0.0), (1, 1, 2.0), (0, -1, -1.0), (1, 0, 3.0), (-1, 1, 7.0), (-1, 0, 3.0), (-1, 1, -6.0), (-1, 1, 2.0), (-1, 0, -4.0), (-1, -1, 1.0), (1, 1, 5.0), (-1, -1, -6.0)], [(1, 1, -1, 1), (0, -1, 5.75), (-1, 1, 2.75), (1, 1, 5.75), (0, 1, -3.25), (-1, -1, -2.25), (0, -1, 3.75), (1, -1, -6.25), (1, 0, 7.75), (1, 1, 1.75), (-1, 1, 6.75), (0, -1, 5.75), (-1, 0, -4.25), (1, 0, -6.25), (0, 0, -4.25), (1, -1, 5.75), (0, 1, 0.75)], [(1, 1, 0, -1), (-1, 0, -1.25), (-1, 0, 6.75), (0, -1, -6.25), (0, 0, -2.25), (-1, 1, 5.75), (-1, 1, 2.75), (0, 1, 6.75), (0, 0, 1.75), (0, 1, -4.25), (1, 1, 8.75), (-1, 1, -6.25), (0, 1, -2.25), (0, 1, 7.75), (-1, -1, -0.25), (1, -1, -0.25), (1, 0, 2.75)], [(1, 1, 0, 0), (-1, -1, -5.5625), (1, 0, 8.4375), (-1, 0, 4.4375), (0, 0, 0.4375), (0, 0, -0.5625), (-1, 1, -0.5625), (0, 0, 1.4375), (0, 1, 4.4375), (1, -1, 7.4375), (1, 1, 4.4375), (0, 1, -4.5625), (1, 0, -2.5625), (1, -1, -5.5625), (-1, 1, -5.5625), (-1, 1, 9.4375), (1, -1, 4.4375)], [(1, 1, 0, 1), (-1, 1, -1.5), (0, 0, 0.5), (1, 1, 5.5), (0, 0, -4.5), (-1, 0, 7.5), (0, 0, -1.5), (1, 0, 4.5), (0, -1, -2.5), (-1, 0, 1.5), (1, 1, -0.5), (1, -1, 7.5), (-1, 0, 4.5), (-1, -1, 6.5), (0, 1, -5.5), (-1, -1, 3.5), (1, 0, -5.5)], [(1, 1, 1, -1), (0, 1, -3.125), (-1, 0, 0.875), (-1, 1, 6.875), (1, 0, -4.125), (0, 1, -5.125), (1, -1, 6.875), (-1, 0, 4.875), (-1, 1, 4.875), (1, 0, 2.875), (-1, 0, -0.125), (1, 0, -2.125), (1, 0, 6.875), (-1, 1, -1.125), (-1, 0, -4.125), (-1, 1, 8.875), (-1, 0, -3.125)], [(1, 1, 1, 0), (0, 0, -1.1875), (1, -1, 8.8125), (1, 1, 6.8125), (1, 0, 3.8125), (0, 1, -2.1875), (1, -1, 7.8125), (1, 1, 3.8125), (-1, -1, 2.8125), (1, 0, -1.1875), (0, 1, -1.1875), (-1, 0, 5.8125), (1, 1, -6.1875), (0, 0, 2.8125), (1, 1, -1.1875), (1, -1, -5.1875), (-1, 1, -4.1875)], [(1, 1, 1, 1), (0, 0, -3.125), (1, 1, 4.875), (-1, 1, -6.125), (-1, 1, 2.875), (0, 1, 1.875), (-1, -1, -5.125), (-1, 1, 2.875), (-1, 1, -2.125), (-1, 1, 3.875), (1, -1, 6.875), (1, 1, 1.875), (1, -1, 2.875), (1, 1, 6.875), (1, 1, 5.875), (0, 1, -2.125), (1, 0, -2.125)]]]
答案 0 :(得分:3)
您永远不会关闭该文件,因为您从不致电file.close()
(请注意括号;您有file.close
)。这可能会弄乱你的文件写作。
更好的是,使用上下文管理器(with
语句),这将确保文件始终关闭,即使在写入过程中发生异常。
with open("test0.txt", "w") as fp:
fp.write(mystr)
See the documentation (end of section)
也就是说,一旦你的脚本结束,文件之类的资源应该由Python自动关闭。但是,我不确定它是否也将任何剩余的文本刷新到这样的文件中。如果没有,那就是问题的原因。