аватар question@mail.ru · 01.01.1970 03:00

How to remove the symbol of the new line (\ n) when reading the lines from the file

when using File.Readlines () we get something like this:

   & gt; & gt; & gt;  file.readlines ()  [ '12 \ n' ,  '10 \ n' ,  '' 9 \ n ',  '' 15 \ n ', ' '10 \ n' ,  '120' ]     

how to remove \ n ?

аватар answer@mail.ru · 01.01.1970 03:00
   & GT; & GT; & GT;  l = [ '12 \ n' ,  '' 10 \ n ', ' '9 \ n' ,  '' 15 \ n ',  '10 \ n' ,  '' 120 ']   & gt; & gt; & gt;  l = [line.rstrip ()  for  line  in  l]   & gt; & gt; & gt;  l [ '12' ,  '10' ,  '' 9 '' '15' ,  '10' ,  '' 120 ']                                       

Latest

Similar