I need to know the size of the file based on file object
import csv
import os
with open("test.csv", "rb") as infile:
reader = csv.reader(infile)
print reader
filesize(reader)
def filesize(reader):
os.getsize(reader) #And i need work with reader for more details.so I must need to pass a reader or file object
When I run this I got an output is
<_csv.reader object at 0x7f5644584980>
From this file object how I get the size of the file?
And I checked this site but these are not CSV attribute size of an open file object
EDIT: When I use that two inbuilt function I got errors that are
AttributeError: '_csv.reader' object has no attribute 'seek' AttributeError: '_csv.reader' object has no attribute 'tell'
Adding this answer because it actually answers the question asked about using the file object directly:
import csv
import os
with open("test.csv", "rb") as infile:
reader = csv.reader(infile)
print reader
infile.seek(0, os.SEEK_END)
filesize = infile.tell()
You can use os.path.getsize or os.stat
import os
os.path.getsize('test.csv')
OR
os.stat('test.csv').st_size
Return the size, in bytes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With