[Pythonmac-SIG] os.linesep?

Just van Rossum just@letterror.com
Tue, 2 Nov 1999 20:10:40 +0100

At 2:04 PM -0500 11/2/99, Chris,Mann wrote:
>No, here's the bit of code that's writing out to a file:
>        file = file + '.all'
>        fileID = open(file, 'w')
>        for bug in self.bugs:
>            if not bug.err:
>                fileID.write(bug.summary(delimiter))
>                fileID.write(linesep)
>                iBugCount = iBugCount + 1
>        fileID.close()
>basically it's a list of strings that i'm writing to the file one line at a
>time.  But if I use os.linesep and then open that text file with BBEdit, it
>says it's a Unix formatted file, not Mac.  I would assume that it would be
>Mac formatted since I'm using os.linesep.

- you're opening your file in text mode ('w' and not 'wb')
- \r and \n will be echanged upon write as well as read
- os.linesep == \r
- so: your file will be indeed be a unix file

So: use \n when in text mode or os.linesep when in binary mode, and you're set.