python bug in this list implementation?

Steven D'Aprano steve at REMOVETHIScyber.com.au
Wed Dec 28 15:42:54 CET 2005


On Wed, 28 Dec 2005 15:07:52 +0100, Christoph Zwerschke wrote:

> Steven D'Aprano wrote:
>> On Wed, 28 Dec 2005 07:29:41 +0000, Chris Smith wrote:
>  >>
>>>def createGrid():
>>>    f = open(r"...sudoku.txt", "rb") ## see attached for the file.
>> 
>> Why do you need a raw string? It isn't wrong to do one, but it is rather
>> unusual and unnecessary.
> 
> Chris is probably working on Windows where it is handy to enter paths as 
> raw strings because of the backslashes. Unusual however, and problematic 
> if you want to use the program on other platforms, is opening a text 
> file in binary mode.

Sure, but then the file name doesn't have any backslashes. 

I've never understood why binary mode is supposed to be bad. By my
understanding, binary mode simply means that no line endings are
translated, regardless of whether the file uses \n, \r or a combination of
the two. Surely the worst that can happen in binary mode is that your
strings end up having some carriage returns you have to deal with yourself?



-- 
Steven.




More information about the Python-list mailing list