简体   繁体   English

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

[英]How to split one very long line in Pycharm into multiple lines?

After parsing, I've got a lot of urls that have unfortunately joined together in one line. 解析之后,不幸的是,我有很多URL在一起排成一行。 It will take a long time to re-parse, so I ask if there is a method as one long line with Url to turn into a multiple lines - 1 Url per line? 重新解析将花费很长的时间,所以我问是否有一种方法,将带有Url的长行变成多行-每行1个Url?

What i have: 我有的:

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

What i need: 我需要的:

'https:// url1.com/bla-1',
'https:// url1.com/bla-2',
etc
'https:// url999.com/bla-N'

I've already tried to uncheck Line breaks in Python - Wrapping and Braces and check Ensure right margin is not exceeded - doesn't work 我已经尝试取消选中Python中的换行符-包装和花括号,并检查确保未超出正确的边距-不起作用

So how can i fix it? 那么我该如何解决呢?

Let's try a simple method, if I understand your query correctly. 如果我正确理解您的查询,请尝试一种简单的方法。 Read the first file, replace commas with newline character, and write the result to the same file. 读取第一个文件,用换行符替换逗号,然后将结果写入同一文件。

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()

Yes. 是。
First set Code->Style->Wrapping and Braces->Method parameters/Method call arguments to wrap if long or chop down if long. 首先设置Code->Style->Wrapping and Braces->Method parameters/Method call argumentswrap if longwrap if long Code->Style->Wrapping and Braces->Method parameters/Method call arguments chop down if long.
After that simply call reformat code on the line (Command+Alt+L). 之后,只需在该行上调用重新格式化代码即可(Command+Alt+L).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM