0
def writeFile(filename):
    prose = r"<?xml version='1.0' encoding='UTF-8'?>"
    startTag = r'<Books>'
    endTag = r'</Books>'
    with open(filename, "+a" ) as f:
        f.write(prose)
        f.write('\n')
        f.write(startTag)
        f.write('\n')
        f.write(endTag)

How do i make this function platform independent so it can work on Windows and Linux/Unix as well Since /n is the new line character on windows.

I am on Python 3.3

jhon.smith
  • 1,865
  • 5
  • 25
  • 44

1 Answers1

6

You need to look in to os module. Especially check os.linesep and os.sep.

os.linesep will give you give correct new line separator, you don't need to check the platorm/os version

os.sep will give you separator for pathname components and again you don't need to check the platform/os version

MA1
  • 2,687
  • 5
  • 33
  • 51