diff --git a/files.html b/files.html index 6419963..a902827 100644 --- a/files.html +++ b/files.html @@ -71,25 +71,21 @@ UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 28: chara
 >>> a_file = open('examples/chinese.txt', encoding='utf-8')
->>> a_file.name                                              
+>>> a_file.name                                              
 'examples/chinese.txt'
+>>> a_file.encoding                                          
+'utf-8'
 >>> a_file.mode                                              
-'r'
->>> a_file.encoding                                         
-'utf-8'
+'r'
    -
  1. FIXME -
  2. -
  3. +
  4. The name attribute reflects the name you passed in to the open() function when you opened the file. It is not normalized to an absolute pathname. +
  5. Likewise, encoding attribute reflects the encoding you passed in to the open() function. If you didn’t specify the encoding when you opened the file (bad developer!) then the encoding attribute will reflect locale.getpreferredencoding(). +
  6. The mode attribute tells you in which mode the file was opened. You can pass an optional mode parameter to the open() function. You didn’t specify a mode when you opened this file, so Python defaults to 'r', which means “open for reading only, in text mode.” As you’ll see later in this chapter, the file mode serves several purposes; different modes let you write to a file, append to a file, or open a file in binary mode (in which you deal with bytes instead of strings).
- +
+

The documentation for the open() function lists all the possible file modes. +

Reading Data From A Text File