Re: python

Pàgina inicial

Reply to this message
Autor: LIGIER Philippe
Data:  
A: jeanluctux, guilde
Assumpte: Re: python
On Tue, 8 Feb 2005 23:10:18 +0100, jeanluc <jeanluctux@???>
wrote:

> OK. J'essaierai de me souvenir pour une autre fois.
> chop() ne vire que le dernier charactere uniquement si celui-ci est '\n'
> ( ou '\r\n' sous windows, j'imagine)
> donc, string.strip() ne convenait pas dans ce cas precis.
>


Si je ne m'abuse, en Perl 'chop' vire SYSTEMATIQUEMENT le dernier caractère
du texte, c'est pourquoi il existe également 'chomp' qui élimine le dernier
caractère uniquement si il est égal à '\n'.

    > perl -e '$t="abcd" ; chop $t ; print $t, "\n"'


        => Affiche : abc


    > perl -e '$t="abcd" ; chomp $t ; print $t, "\n"'


        => Affiche : abcd


    > perl -e '$t="abcd\n1234" ; chop $t ; print $t, "\n"'


        => Affiche : abcd
                         123


    > perl -e '$t="abcd\n1234" ; chomp $t ; print $t, "\n"'


        => Affiche : abcd
                         1234