seek(offest[n, from]) method 改變目前的讀寫位置,n 是移動的 bytes 數,from 是開始的位置,from 設定值:
[dywang@deyu zzz]$ cat fileio5.py
#!/usr/bin/python3
fo = open("fileio.txt", "r+")
print("Read 10 bytes is:", fo.read(10))
print("Current file position:", fo.tell())
fo.seek(0,0)
print("Current file position after seek:", fo.tell())
print("Again read 10 bytes is:", fo.read(10))
fo.close()
[dywang@deyu zzz]$ ./fileio5.py Read 10 bytes is: Python 是很棒 Current file position: 16 Current file position after seek: 0 Again read 10 bytes is: Python 是很棒