Jump to content
  • Advertisement
Sign in to follow this  

Inserting a Newline into a File

This topic is 4577 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know this is the stupidest question probably every posed on this forum...but here goes. (By the way I am working in python) When working with files, how do u insert a newline? I tried stuff like /n and /r/n but it just writes it into the file without the actualy new line so instead of: phlash studios I get: phlash/r/nstudios How do I a new line into a file? lol thanks in advance

Share this post

Link to post
Share on other sites
Well, if python follows the C style escape sequences, then you should use "\" rather than "/".

So you would write \n or \r\n.

That is assuming it follows the c style. [grin]

Good Luck!

Share this post

Link to post
Share on other sites
Did you disable it during configuration? This article might be helpful:


Universal newline support is enabled by default,
but can be disabled during the configure of Python.

In a Python with universal newline support the feature is
automatically enabled for all import statements and execfile()
calls. There is no special support for eval() or exec.

In a Python with universal newline support open() the mode
parameter can also be "U", meaning "open for input as a text file
with universal newline interpretation". Mode "rU" is also allowed,
for symmetry with "rb". Mode "U" cannot be
combined with other mode flags such as "+". Any line ending in the
input file will be seen as a '\n' in Python, so little other code has
to change to handle universal newlines.

Conversion of newlines happens in all calls that read data: read(),
readline(), readlines(), etc.

There is no special support for output to file with a different
newline convention, and so mode "wU" is also illegal.

A file object that has been opened in universal newline mode gets
a new attribute "newlines" which reflects the newline convention
used in the file. The value for this attribute is one of None (no
newline read yet), "\r", "\n", "\r\n" or a tuple containing all the
newline types seen.

(Taken from http://www.python.org/dev/peps/pep-0278/)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!