我有这个密码:
file = open('scores.txt','w')
playerscores = []
playernames = [['A'],['B'],['C'],['D'],['E'],['F']]
for y in range(6):
for z in range(5):
print("Enter score from Judge",z+1,"for couple ",playernames[0+y],"in round 1:")
playerscores.append(int(input()))
MY_LIST = str(playerscores)
for_every = 4
基本上,我想通过在新行上打印以下索引位置来写入文件
playerscore[0:6]
playerscore[7:13]
等等
所以看起来像:
1,1,1,1,1,1,1,1,1,1
而不是[1,1,1,1,1,1]
我需要这样做,当我这样做
file = open('filename','r')
而且叫一个位置,很容易就发出来了。你知道吗
这里有一些代码可以满足您的需要,尽管它从我的
get_data()
函数而不是从input()
获取数据。这使得代码更易于测试。但是一旦完成了程序的开发,就可以很容易地用input()
替换get_data()
调用。你知道吗关键思想是,除了将输入数据的整数版本保存到
playerscores
之外,我们还将其以原始字符串形式保存在名为row
的单独列表中。因此,当我们读取完给定行的数据后,就可以轻松地将其保存到文件中。这比尝试将数据从playerscores
拆分并将其转换回字符串要简单。你知道吗典型输出
内容分数.txt
如果我理解正确的话,你在找这样的东西:
相关问题 更多 >
编程相关推荐