Re: [問題] i/o file tell() 問題
※ 引述《zha0 (這個帳號是掛網用)》之銘言:
: ifile = open('c:/x/x.txt, 'rb')
: ifile.seek(0, 2)
: ifile_s = ifile.tell()
: ifile.seek(0, 0)
: print "%d = %d" % (ifile_s, ifile.tell())
: 為什麼出來的東西不是檔案大小 ?
: 3743456 = 0
ifile.seek(0, 2) # 移到檔案尾部
ifile_s = ifile.tell() # 所以回傳檔案大小,也就是 3743456
ifile.seek(0, 0) # 移到檔案開頭
print(ifile.tell()) # 應該得到 0
所以程式碼結果看起來是對的... 還是我誤解了什麼?
: 在 python GUI 他不會有錯 , 但寫成 *.py 執行起來就取不到正常檔案的大小 ?
: PS. Verion python 2.7
: fi = open(path,'rb')
: fi_s = os.path.getsize(path)
: print fi_s
: 為什麼連這樣取大小都會有錯 T_T 所在目錄的路徑沒有中文全都英文 .
我這裡環境是 Win 7 x64 + Python 2.7.1 一切正常耶 @@
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.166.121.37
推
12/22 00:56, , 1F
12/22 00:56, 1F
→
12/22 00:57, , 2F
12/22 00:57, 2F
Python 近期熱門文章
PTT數位生活區 即時熱門文章