所以我正在逐行读取一个csv文件。在每一行中,我逐个字段并尝试获取每个字段的大小(以字节为单位)起诉.getsizeof。代码如下:
for row in reader:
temp1 = []
temp2 = []
if type(row[0]) is IntType:
feed = feed + 1
print feed
# Total number of columns in a feed should be 61.
# 61st column account for the last , after 60th column, it would always be blank.
#if len(row) == 61:
# Total number of columns in a feed should be 61
for field in row:
if type(field) == 'int':
field.encode('ascii', 'ignore')
temp1.append(sys.getsizeof(field))
temp2.append(str(field))
else:
field = [unicode(field)]
#field = field.encode('ascii', 'ignore')
temp1.append(sys.getsizeof(field))
temp2.append(str(field))
由于某种原因,所有行中每个字段的大小都为 40。知道为什么吗?