如何将Pycharm中的一个很长的行拆分成多个行?

2024-10-02 20:31:38 发布

您现在位置:Python中文网/ 问答频道 /正文

解析之后,我得到了很多不幸地连接在一行的url。重新解析需要很长的时间,所以我问是否有一个方法作为一个带有Url的长行来转换成多行-每行1个Url?在

我所拥有的:

'https:// url1.com/bla1','https:// url1.com/bla2',..thousands of urls..,'https:// url999.com/blaN'

我需要的是:

^{pr2}$

我已经尝试取消选中Python中的换行符-换行符和大括号,并检查确保不超过右边距-不起作用

那我该怎么解决呢?在


Tags: of方法httpscomurl时间urlspr2
2条回答

如果我能正确理解您的查询,让我们尝试一个简单的方法。读取第一个文件,用换行符替换逗号,然后将结果写入同一个文件。在

urlsfile = open('test1.txt', 'r+') # in case you are getting the data from file itself
urls = urlsfile.readline()
urlsfile.close()
newlines = urls.replace(",", "\n") # otherwise replace newlines with the variable name that you are trying to write to the file
newfile = open('test1.txt','w+')
newfile.write(newlines)
newfile.close()

是的。
首先将Code->Style->Wrapping and Braces->Method parameters/Method call arguments设置为wrap if longchop down if long.
之后,只需在(Command+Alt+L).行调用reformat code

相关问题 更多 >