----- Messaggio originale ----- > Da: "Valerio Pachera" <vale...@pbds.eu> > A: "Tutor Python" <tutor@python.org> > Inviato: Giovedì, 28 febbraio 2019 13:05:27 > Oggetto: Re: [Tutor] Remove soft line break >... > It works as expected but there's a thing I've to understand about the end of > line in general. > ... > I noticed that the end of file doesn't get preserve if I create a copy of the > file by simply > > f = open('file.ics') > content=f.read() > f.close() > > f = open('file_copy.ics', 'w') > write('content') > f.close()
Got it! Python automatically convert new line to \n when it opens the file open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None) This is my final script that overrides the original file. --- import sys f = open(sys.argv[1], newline='\r\n') content = f.read().replace('\r\n ', '') f.close() f = open(sys.argv[1], 'w') f.write(content) f.close() --- Valerio P. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor