python清空列表
  1. 在非函数参数的list中使用del list_new[]或者list_new = []来清空列表
  2. 对于作为函数中的list,方法1行不通,因为函数执行后,list长度是不变的,但是可以在函数中释放一个参数list所占内存:del list_new[:]或者list_new[:] = []达到清空列表的目的,速度快,并且彻底
查看对象占用内存大小

os.getsizeof(1.0)

类型转换
import struct
    import math
    print("1000.003 is %s" %(int(struct.pack('>f', 1000.003).encode('hex'), 16)))
    print("1000.003 is %s" %(struct.pack('>I', 1000)))
    #print("1000.003 is %d" %(int(floor(1000.003))))

IEEE 754标准是IEEE二进制浮点数算术标准(IEEE Standard for Floating-Point Arithmetic)的标准编号,它规定了浮点数在计算机当中的存储方式以及算术标准.
计算机中数据均是按二进制的方式存储的,浮点数的存储也是如此.但是由于浮点数的特殊性,无法采用整数的补码存储方式,浮点数需要有特定的存储方式.一个浮点数可以分成3部分存储:

  • sign(符号)
  • exponent(指数)
  • fraction(尾数)

https://en.wikipedia.org/wiki/IEEE_754-1985

模块导入

本地模块名和系统库模块名冲突报:
ImportError: cannot import name AttrItem


import configparser 
print configparser.__file__

自定义configparser与系统冲突,通过打印__file__查看