why python doesn't have a writeline() method like c# ?

C

Chris Rebert

just curious, it would make writing to a file  a bit easier?

Because we have print(), which adds the newline, and most other cases
either involve lists of stuff (so '\n'.join() is used), or the string
comes back from a library and already has newlines, so you just write
the string verbatim.

Sidenote: file.writelines() seems very misleadingly named.

Cheers,
Chris
 
B

Benjamin Peterson

ww said:
just curious, it would make writing to a file a bit easier?

Because readline() returns the line with the newline attached, writeline() would
have to require a newline at the. Therefore, it would be equivalent to write()!

Just use f.write("some line\n").
 
B

Benjamin Peterson

Chris Rebert said:
Sidenote: file.writelines() seems very misleadingly named.

Indeed since it is basically a shortcut for f.write("".join(lines)).
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top