Parse textarea line by line (or a specific line #) with Django
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]
精彩评论