supressing '\n' at the end

Discussion in 'Python' started by SunX, Nov 6, 2004.

  1. SunX

    SunX Guest

    Gurus;
    I need some help here. How do you supress the newline char. at the
    end of a file.write(str(aString))? I know you can add a newline by
    simply doing file.write(str(aString) + '\n'), but not
    file.write(str(aString) - '\n').
    Thanks alot
    Howard
    SunX, Nov 6, 2004
    #1
    1. Advertising

  2. SunX wrote:
    > Gurus;
    > I need some help here. How do you supress the newline char. at the
    > end of a file.write(str(aString))? I know you can add a newline by
    > simply doing file.write(str(aString) + '\n'), but not
    > file.write(str(aString) - '\n').


    Where does the \n come from? I presume the 'aString' object contains
    it. Then you can do:

    file.write(aString[:-1])

    (but only if aString always contains a '\n' at the end, ofcourse)

    --Irmen
    Irmen de Jong, Nov 6, 2004
    #2
    1. Advertising

  3. Irmen de Jong wrote:
    > Where does the \n come from? I presume the 'aString' object contains
    > it. Then you can do:
    >
    > file.write(aString[:-1])
    >
    > (but only if aString always contains a '\n' at the end, ofcourse)


    file.write(aString.rstrip('\n'))

    seemes more natural and safer to me.

    -- George
    George Yoshida, Nov 6, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Herb Stull

    Supressing Menu and Toolbars on Webpage

    Herb Stull, Feb 25, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    498
    Eric Lawrence [MSFT]
    Feb 25, 2004
  2. Dave

    Supressing sign extension

    Dave, Oct 9, 2004, in forum: C++
    Replies:
    4
    Views:
    700
    Alf P. Steinbach
    Oct 10, 2004
  3. Michael B Allen

    Supressing Unused Parameter Warnings

    Michael B Allen, May 7, 2004, in forum: C Programming
    Replies:
    11
    Views:
    1,018
    CBFalconer
    May 8, 2004
  4. Jp Calderone

    Supressing PyChecker warnings

    Jp Calderone, Jan 16, 2004, in forum: Python
    Replies:
    1
    Views:
    470
    Rene Pijlman
    Jan 16, 2004
  5. Mark Harrison

    supressing warning message?

    Mark Harrison, Jul 29, 2004, in forum: Python
    Replies:
    2
    Views:
    449
    Mark Harrison
    Jul 29, 2004
Loading...

Share This Page