others - 在 python 中,如何逐行读取长多行字符串

如何用for逐行读取? for line in textData


for line in textData
 print line
 lineResult = libLAPFF.parseLine(line)

时间:

如何使用.splitlines()


for line in textData.splitlines():
 print(line)
 lineResult = libLAPFF.parseLine(line)

通过换行符拆分。


for line in wallop_of_a_string_with_many_lines.split('n'):
 #do_something..

如果您遍历字符串,则是在该字符串中逐字符而不是逐行遍历。


>>>string = 'abc'
>>>for line in string:
 print line

a
b
c


import re

s = 
"""line1
line2
line3
"""

lines = re.split('n',s)
print lines
for line in lines:
 print line

...