tags:

views:

73

answers:

2

Hi, I would like to parse the content of a textarea in my django view, line by line (or get a specific line number). Thanks

+1  A: 
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]
Ofri Raviv
+2  A: 

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

Peter Bengtsson