Perl chop equivalent in Python?
Fredrik Lundh
effbot at telia.com
Wed May 31 15:13:01 EDT 2000
pem at my-deja.com> wrote:
> Is there an equivalent command to chop (the perl command) in Python? If
> not, is there some easy way to use existing commands to do this simple
> task? I need to do it frequently and would like to have a readily
> available command that does not require much programming. Thanks in
> advance.
www.python.org => search => newsgroup search for
"chop" => a whole bunch of hits, including this one by
François Pinard:
http://www.deja.com/=dnc/getdoc.xp?AN=583863832
...
To chop (even if line is truly empty):
line = line[:-1]
To chomp:
if line and line[-1] == '\n':
line = line[:-1]
...
</F>
More information about the Python-list
mailing list