我正在讀取一個沒有熊貓庫的 csv 檔案,我需要找出每行的位元組數。所以我可以廣告所有位元組并確定檔案大小,并會在此基礎上做一些限制。
file="Emptycsv.csv"
checkfilesize(file)
def checkfilesize(file):
file=b''join(file).split(b'\n')
count=len(file)
計數將列印行數。我需要找出檔案大小,我知道 os.path.getsize 會這樣做..但是在逐行/列或列讀取該 csv 檔案時,如果它達到 109997897kb,我需要終止.所以請求你幫我找到資料的位元組
uj5u.com熱心網友回復:
與此類似的東西應該適用于獲取每行/行的位元組數:
( 1 用于換行符)
import os
total_bytes = -1
with open("test.csv") as file_in:
for line in file_in:
bytes_on_this_line = len(line) 1
total_bytes = bytes_on_this_line
print(total_bytes)
print(os.path.getsize("test.csv"))
輸出:
15
15
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/475897.html