我想从文件中添加一个值到列表,然后能够将文件中的值添加到列表中。 这是我有:Python文件,将值添加到/从列表
L = []
def readFile(L):
ui = input("Please enter your file name:")
r = open(ui, 'r')
files = r.readlines()
for line in files:
return float(line)
L.append(line)
r.close()
def fileAddValue(L):
ui = input("Please enter your file name:")
val = float(input("Enter the value you would like to add to the list: "))
r = open(ui, 'a')
file = r.write(str(val) + '\n')
for ix in r:
x = float(ix)
L.append(x)
L.sort()
r.close()
你的问题是什么? –
对不起,我不清楚。我只是想弄清楚如何读取文件中的值并将它们存储在列表和签证经文中。错误后我不断收到错误。 – juhnellove