标签:collect 表示 point -128 random 文件 extend add cccccc
Type code C Type Minimum size in bytes ‘b‘ signed integer 1 ‘B‘ unsigned integer 1 ‘u‘ Unicode character 2 ‘h‘ signed integer 2 ‘H‘ unsigned integer 2 ‘i‘ signed integer 2 ‘I‘ unsigned integer 2 ‘l‘ signed integer 4 ‘L‘ unsigned integer 4 ‘q‘ signed integer 8 ‘Q‘ unsigned integer 8 ‘f‘ floating point 4 ‘d‘ floating point 8
>>> from array import array >>> from random import random >>> floats = array(‘d‘, (random() for i in range(10**7))) >>> floats[-1] 0.021901117799701275 >>> fp = open(‘floats.bin‘, ‘wb‘) >>> floats.tofile(fp) >>> fp.close() >>> floats_2 = array(‘d‘) >>> fp = open(‘floats.bin‘, ‘rb‘) >>> floats_2.fromfile(fp, 10**7) >>> fp.close() >>> floats_2[-1] 0.021901117799701275 >>> floats_2 == floats True
>>> import array >>> a = array.array(a.typecode, sorted(a))
标签:collect 表示 point -128 random 文件 extend add cccccc
原文地址:https://www.cnblogs.com/haoqirui/p/9977031.html