supressing '\n' at the end

S

SunX

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
 
I

Irmen de Jong

SunX said:
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
 
G

George Yoshida

Irmen said:
> 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top