开发者

Parse textarea line by line (or a specific line #) with Django

开发者 https://www.devze.com 2022-12-14 13:33 出处:网络
I would like to parse the content of a textarea in my django view, line by line (or get 开发者_如何转开发a specific line number).

I would like to parse the content of a textarea in my django view, line by line (or get 开发者_如何转开发a specific line number). Thanks


Use text_area_value.splitlines() instead. Then you don't have to worry about \r\n or \n issues. Also, it reads better.


for line in text_area_value.split('\n'):
    # do something with line

or if you want a specific number (3 in this example - which is the 4th line, counting the "human" way):

lines = text_area_value.split('\n')
    # do something with lines[3]
0

精彩评论

暂无评论...
验证码 换一张
取 消