How you chomp in python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fernando Armenta

    How you chomp in python

    How you cut off the ^M at the end of a line? rstrip is not working.



    string.rstrip(b uild_number)



    thanks,



    -F










  • Pete Jereb

    #2
    Re: How you chomp in python

    "Fernando Armenta" <farmenta@pilla rdata.com> wrote in message news:<mailman.1 064022207.30931 .python-list@python.org >...[color=blue]
    > How you cut off the ^M at the end of a line? rstrip is not working.
    >
    >
    >
    > string.rstrip(b uild number)
    >[/color]


    Do you mean the newline character? If your string variable is named
    build_number, then

    build_number = build_number.rs trip('/n')

    works. Sorry if this isn't what you meant. But the format should be
    the same. If you did mean ^M then perhaps a hex or octal
    representation?

    Comment

    • JZ

      #3
      Re: How you chomp in python

      On Fri, 19 Sep 2003 18:43:14 -0700, "Fernando Armenta"
      <farmenta@pilla rdata.com> wrote:
      [color=blue]
      >How you cut off the ^M at the end of a line? rstrip is not working.[/color]

      chomp in Perl change the string in place
      rstrip in Python is method, it does NOT change the string in place
      [color=blue][color=green][color=darkred]
      >>> s = "abc\n"
      >>> s.rstrip()[/color][/color][/color]
      'abc'[color=blue][color=green][color=darkred]
      >>> s[/color][/color][/color]
      'abc\n'[color=blue][color=green][color=darkred]
      >>> s = s.rstrip()[/color][/color][/color]
      'abc'

      --
      JZ

      Comment

      • JZ

        #4
        Re: How you chomp in python

        On Fri, 19 Sep 2003 18:43:14 -0700, "Fernando Armenta"
        <farmenta@pilla rdata.com> wrote:
        [color=blue]
        >How you cut off the ^M at the end of a line? rstrip is not working.[/color]

        Strings in Perl are mutable so chomp() change the string in place.
        Strings in Python are *not* mutable, so rstrip() does *not* change
        the string in place.
        [color=blue][color=green][color=darkred]
        >>> s = "abc\n"
        >>> s.rstrip()[/color][/color][/color]
        'abc'[color=blue][color=green][color=darkred]
        >>> s[/color][/color][/color]
        'abc\n'[color=blue][color=green][color=darkred]
        >>> s = s.rstrip()[/color][/color][/color]
        'abc'

        --
        JZ

        Comment

        Working...