我正在尝试在将数字添加到文件中的另一个数字时修复我的代码上的错误

时间:2022-10-07 20:22:18

I have a file like this:

我有这样一个文件:

  RubyWilson,20,174.0,female,23.45,1562.41,**367**

I'm trying to add a number to the last number in the file like this:

我正在尝试将数字添加到文件中的最后一个数字,如下所示:

  number = 300

  RubyWilson,20,174.0,female,23.45,1562.41,**667**

This is what I've tried so far:

这是我到目前为止所尝试的:

  name = input("name")
  FitnessFile = open((name + "fitness file.csv") , "r")
  myVar = FitnessFile.read()
  FitnessFile.close()
  myList = myVar.split(",")
  number = int(input("enter number"))
  str(myList[6])) = int(myList[6]) + (number)

  FitnessFile = open((name + "fitness file.csv") , "w")
  addList = ",".join(myList)
  FitnessFile.write(addList)
  FitnessFile.close()

When I run it, it says can't assign function call on line 6.

当我运行它时,它说不能在第6行分配函数调用。

How do I fix this?

我该如何解决?

1 个解决方案

#1


I suspect you want to replace

我怀疑你想要更换

str(myList[6])) = int(myList[6]) + (number)

which, by the way, isn't even syntactically valid, with

顺便说一句,这在语法上是无效的

myList[6] = str(int(myList[6]) + (number))

However, none of this takes care of the asterisks. Do they actually appear in your data?

但是,这些都不会照顾星号。它们确实出现在您的数据中吗?

#1


I suspect you want to replace

我怀疑你想要更换

str(myList[6])) = int(myList[6]) + (number)

which, by the way, isn't even syntactically valid, with

顺便说一句,这在语法上是无效的

myList[6] = str(int(myList[6]) + (number))

However, none of this takes care of the asterisks. Do they actually appear in your data?

但是,这些都不会照顾星号。它们确实出现在您的数据中吗?