[Tutor] code improvement for beginner ?

Kent Johnson kent37 at tds.net
Mon Oct 10 23:25:23 CEST 2005


Roel Schroeven wrote:
> Danny Yoo wrote:
> 
>>Looking at pageimgs(): I'm not sure what 't' means in the open statement:
>>
>>	f = open(filename, "rt")
> 
> It's not a typo. 't' opens the file in text mode. 

Are you sure? Is that documented anywhere?

Text mode is the default, you have to specify the 'b' if you want binary mode. And open() seems to accept any mode quite happily:

 >>> f=open('build.xml', 'rt')
 >>> f
<open file 'build.xml', mode 'rt' at 0x0096C9B0>
 >>> f.close()
 >>> f=open('build.xml', 'rabcd')
 >>> f
<open file 'build.xml', mode 'rabcd' at 0x0096C9F8>

Kent



More information about the Tutor mailing list