perl chomp equivalent in python?

Gerrit Holl gerrit.holl at pobox.com
Thu Feb 10 15:21:21 EST 2000


Emile van Sebille wrote on 950116589:
> Kees,
> 
> Try this:
> 
> >>> lines = open(r'c:\config.sys').readlines()
> 
> >>> for line in lines:
>  print line[:-1]

Incorrect :(

>>> 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

-- 
Homepage: http://www.nl.linux.org/~gerrit
-----BEGIN GEEK CODE BLOCK----- http://www.geekcode.com
Version: 3.12
GCS dpu s-:-- a14 C++++>$ UL++ P--- L+++ E--- W++ N o? K? w--- !O
!M !V PS+ PE? Y? PGP-- t- 5? X? R- tv- b+(++) DI D+ G++ !e !r !y
-----END GEEK CODE BLOCK----- moc.edockeeg.www//:ptth




More information about the Python-list mailing list