我有一個(gè)python文件,其中有很多這樣的雙括號(hào),我想用單括號(hào)代替。有時(shí)打印會(huì)持續(xù)進(jìn)行2行或更多行。print(('>> # some text some text some text and ' + 'some more text'))print(('>> # some text some text some text and ' + 'some more text'))print(('>> # some text some text some text and ' + 'some more text'))print(('>> # some text some text some text and ' + 'some more text'))print((something))print((something))print((something))print((something))print((something))print((something))我嘗試了很多不同的方法來解決這個(gè)問題。我認(rèn)為最簡(jiǎn)單的方法是使用sed。我有這樣的事情:grep -rl 'print((' test.txt | xargs sed -i "N;s/print((\(.*\)))/print(\1)/g"輸出看起來像這樣:print('>> # some text some text some text and ' + 'some more text')print('>> # some text some text some text and ' + 'some more text')print(('>> # some text some text some text and ' + 'some more text'))print(('>> # some text some text some text and ' + 'some more text'))print(something)print(something)print(something)print(something)print(something)print(something)現(xiàn)在有一些行可以工作,但有一些行卻不行,我認(rèn)為這是因?yàn)镹。但如果有多行,我需要這個(gè)..我該怎么做才能改善這種模式?
添加回答
舉報(bào)
0/150
提交
取消