Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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
Python3-如何用列表中某个索引处的str替换str_Python_Python 3.x - Fatal编程技术网

Python3-如何用列表中某个索引处的str替换str

Python3-如何用列表中某个索引处的str替换str,python,python-3.x,Python,Python 3.x,我试图循环浏览一个csv文件,并从第一列中的项目中删除“-”。我还做了一些其他的清理更改,对这个q来说也不重要。尝试使用str.replace函数时出现语法错误 with open('fron.csv', newline='') as f: reader = csv.reader(f) for row in reader: del row[10:] del row[8] del row[5:7] del row[2:

我试图循环浏览一个csv文件,并从第一列中的项目中删除“-”。我还做了一些其他的清理更改,对这个q来说也不重要。尝试使用str.replace函数时出现语法错误

with open('fron.csv', newline='') as f:
    reader = csv.reader(f)
    for row in reader:
        del row[10:]
        del row[8]
        del row[5:7]
        del row[2:4]
        row[0] = row[0].replace('-',''))
        row.append('Fron')
        newlist.append(row)
print(newlist)
以下代码行的语法不正确

row[0] = row[0].replace('-',''))
我可以做到以下几点,而且效果很好:

row[0] = '1'
我错过了什么

行[0]=行[0]。替换“-”

此行末尾有额外的右括号。

它应该是第[0]=行[0]。替换“-”,而不是第[0]=行[0]。替换“-”

删除额外的右括号

这将有助于:


第[0]行=第[0]行。替换“-”,

附加括号->第[0]行。替换“-”,你有没有在公共场合问过一个非常愚蠢的问题,然后想消失。。。。。。。。