爱沙尼亚国民身份证号码处理库
estnin的Python项目详细描述
用于处理爱沙尼亚国民身份号码的python库。
安装
使用pip安装:
pip install estnin
文件
运行测试
python setup.py test
用法
创建新的estnin实例:
>>> from estnin import estnin >>> person = estnin(37001011233) >>> print(person.sequence) >>> 123 >>> print(estnin(estnin.MIN)) >>> 10001010002 >>> person = estnin.create(estnin.MALE, date(1970, 1, 1), 1) >>> print(person) >>> 37001010018
str()
>>> assert estnin(37001010018) == "37001010018"
int()
>>> assert estnin(37001010018) == 37001010018
<;,==,>;
>>> assert estnin(37001011233) < estnin(estnin.MAX) >>> assert estnin(37001011233) > estnin(estnin.MIN) >>> assert estnin(37001011233) == estnin(37001011233)
否定
否定的定义是将性别从男性变为女性或副女性。
>>> assert -estnin(37001011233) == estnin(47001011234)
加和减
添加一个整数将序列值按给定的量递增。如果序列和给定的数字之和大于999,则天将递增,余数将设置为新的序列值。日期、月份和年份值按时间顺序递增,直到达到所定义的最大值。如果年份跨越世纪边界,那么世纪数字也被正确设置。
>>> assert estnin(37001011244) == estnin(37001011233)+1 >>> assert estnin(37001011244) == estnin(37001011255)-1 >>> # Create new person >>> person = estnin.create(estnin.MALE, date(1999, 12, 31), 999) >>> print(person) >>> 39912319997 >>> assert estnin(50001010006) == person+1
迭代
遍历给定的estnin实例将创建新对象。
>>> people = [p for _, p in zip(range(3), estnin(37001011233))] >>> print(' '.join(map(str, people))) >>> 37001011233 37001011244 37001011255
可以使用方法reversed():
>>> people = [p for _, p in zip(range(3), reversed(estnin(37001011233)))] >>> print(' '.join(map(str, people))) >>> 37001011233 37001011222 37001011211
属性
>>> person = estnin.create(estnin.MALE, date(1970, 1, 2), 3) >>> person 37001020036 >>> person.century 3 >>> person.year 1970 >>> person.month 1 >>> person.day 2 >>> person.sequence 3 >>> person.checksum 6 >>> person.date datetime.date(1970, 1, 2)