read method

  1. read method 從開啟的檔案物件中讀取字串, count 是讀取的字數,不給count則讀取整個檔案。
    fileObject.read([count])
    
  2. 範例:第一次讀3做字,接著讀 10個字。
    [dywang@deyu zzz]$ cat fileio4.py 
    #!/usr/bin/python3
    
    fo = open("fileio.txt", "r+")
    print("Read 3 bytes is:", fo.read(3))
    print("Read 10 bytes is:", fo.read(10))
    fo.close()
    
  3. 執行結果:
    [dywang@deyu zzz]$ ./fileio4.py 
    Read 3 bytes is: Pyt
    Read 10 bytes is: hon 是很棒的程式