Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更新文本文件python中的一行时,对象不可编辑_Python - Fatal编程技术网

更新文本文件python中的一行时,对象不可编辑

更新文本文件python中的一行时,对象不可编辑,python,Python,我正试图根据上一行更新文本文件中的一行,但当我尝试更新该行时,会出现“object not iterable”错误。 该文件如下所示: _收入= 十, 有人就座= 一, 剩余座位= 199_ 我的代码: FileRead = open(self.fileName, "r") lines = FileRead.readlines() print(lines) for i in range(len(lines)): if "Re

我正试图根据上一行更新文本文件中的一行,但当我尝试更新该行时,会出现“object not iterable”错误。 该文件如下所示:

_收入=

十,

有人就座=

一,

剩余座位=

199_

我的代码:

FileRead = open(self.fileName, "r")
        lines = FileRead.readlines()
        print(lines)
        for i in range(len(lines)):
            if "Revenue" in lines[i]:
                print("good")
                self.revenue = self.revenue + self.AdditionalRevenue
                print(lines[i+1])
                place = i+1
                lines.insert(place, self.revenue)
        FileRead.close()

        FileWrite = open(self.fileName, "w")
        FileWrite.writelines(lines)
        FileWrite.close()

以“r”->只读方式打开文件,然后尝试写入;)请提供完整的错误信息message@veselindanilov不正确。它将如何更新?它将插入一个新对象。您可能需要执行
行[i+1]=self.revenue