我有一个 .csv 文件,其中可能混合了括号:
line = "fdf,dfdf,(1,2,3,4,5),(ss,dd),"
现在我想将所有的 () 替换为“”,使其看起来像这样:
line = 'fdf,dfdf,"1,2,3,4,5","ss,dd",'
我的代码是:
line=re.sub(',(', ',"', line)
line=re.sub('),', '",', line)
但是我收到了这个错误:
...
File "/usr/local/Python-2.7/lib/python2.7/re.py", line 151, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "/usr/local/Python-2.7/lib/python2.7/re.py", line 242, in _compile
raise error, v # invalid expression
sre_constants.error: unbalanced parenthesis
这里有什么问题?!!