python - rstrip not removing newline char what am I doing wrong? -


By dragging my hair here ... for the last hours this is playing with, but what do I do to I can not get the I want, ie remove the new line sequence ifile = open (fpath, 'r') oilil = open ('ofile.txt', 'w') for line for ifile: if line == '

  def add_quotes (fpath) \ N': ofile.write ("\ n \ n") Elph Lane (line)> 1: line.rstrip ('\ n') outline = "\" "+ line +" \ "," oilil. Written (converted line) ifile.close () offline.co.j ()  

The sign is in the sign of rstrip .

This is a copy of the string, but it has been stripped with the desired characters, so you have to specify the new value of line :

  Line = line.rstrip ('\ n')  

This allows for very easy chains of operations multiple times:

  "A string ".strip () As the observations say, the Python string is irreversible, which means that any "mutated" operation will produce a mutated copy. 

It does this in many types of structures and languages. If you really need a temporary string type (usually for display reasons), then there are string buffer classes.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -