perl chomp equivalent in python?

Fred L. Drake, Jr. fdrake at
Thu Feb 10 15:35:26 EST 2000

Gerrit Holl writes:
 > >>> import os
 > >>> lines = open("path-to-file", 'r').readlines()
 > >>> for line in lines:
 > ...     print line[:len(os.linesep)]
 > cross-platformness-rules-ly y'rs - gerrit

  This won't work on DOS or Windows.  os.linesep is two characters,
but the line will only contain a '\n', since the file was opened in
text mode.  The original code was fine.  ;)


Fred L. Drake, Jr.	  <fdrake at>
Corporation for National Research Initiatives

More information about the Python-list mailing list