Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > supressing '\n' at the end

Reply
Thread Tools

supressing '\n' at the end

 
 
SunX
Guest
Posts: n/a
 
      11-06-2004
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
 
Reply With Quote
 
 
 
 
Irmen de Jong
Guest
Posts: n/a
 
      11-06-2004
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
 
Reply With Quote
 
 
 
 
George Yoshida
Guest
Posts: n/a
 
      11-06-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Supressing sign extension Dave C++ 4 10-10-2004 04:36 AM
supressing warning message? Mark Harrison Python 2 07-29-2004 05:16 PM
Supressing Unused Parameter Warnings Michael B Allen C Programming 11 05-08-2004 08:21 AM
Supressing Menu and Toolbars on Webpage Herb Stull ASP .Net 3 02-25-2004 06:32 PM
Supressing PyChecker warnings Jp Calderone Python 1 01-16-2004 09:07 PM



Advertisments