Python Html删除行首的空白
我有一条被线分开的线Python Html删除行首的空白,python,html,python-3.x,string,Python,Html,Python 3.x,String,我有一条被线分开的线 testString = "This is line 1\nThis is line 2\n -Description\n -Description2" 如何在不减少行首空白的情况下实现 谢谢你的帮助 您可以使用。拆分线: 输出: ['This is line 1', 'This is line 2', ' -Description', ' -Description2'] 正如Martin在问题的评论部分所指出的,问题不在于python函数拆分行。我
testString = "This is line 1\nThis is line 2\n -Description\n -Description2"
如何在不减少行首空白的情况下实现
谢谢你的帮助 您可以使用。拆分线:
输出:
['This is line 1', 'This is line 2', ' -Description', ' -Description2']
正如Martin在问题的评论部分所指出的,问题不在于python函数拆分行。我在html中使用该字符串时遇到了一个问题,没有剪切空格
不,split方法不会删除任何空白。无论您使用testString.split\n还是testString.splitlines,空白都会保留。你用什么来去除它们?啊,是的。你是对的。我使用Django在html模板中显示字符串。问题是html。我发现如果不应该剪切空白,就需要实现解决方案p{whitespace:pre;}。感谢您指出分割线功能不是问题!
['This is line 1', 'This is line 2', ' -Description', ' -Description2']