How to write dos newline in unix?

I

Inyeol Lee

Is there any simple way to dos-style newline (\r\n) in *nix environment,
not by writing "\r" explicitly? What I'm trying to do is;

ofile = file("foo", "w")
print "hello, world"

Then it writes "hello, world\r\n".

I tried to assign "\r\n" to ofile.newlines but failed because it's
read-only attribute.

Inyeol Lee
 
P

Peter Otten

Inyeol said:
Is there any simple way to dos-style newline (\r\n) in *nix environment,
not by writing "\r" explicitly? What I'm trying to do is;
.... def __init__(self, dest):
.... self.dest = dest
.... def write(self, s):
.... self.dest.write(s.replace("\n", "\r\n"))
.... def __getattr__(self, name):
.... return getattr(self.dest, name)
....'so what\r\nwill this print?\r\n'

Simple enough?

Peter
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top