首页 > 代码库 > pay包注释(一)
pay包注释(一)
lovep2c项目pay模块注释:
views.py:
def create_user_no(email):
return md5(email).hexdigest().upper() + "".join([choice(string.letters) for i in range(8)])
/*
* md5(email).hexdigest().upper() 用md5算法对email进行加密,采用十六进制数并将其转化为大写
* print (hashlib.md5(‘451314789@qq.com‘)) === <md5 HASH object @ 0xa0936b0>
* print (hashlib.md5(‘451314789@qq.com‘).hexdigest()) === 1d289b39ecb32b5e3dc4a7463e20d030
* print (hashlib.md5(‘451314789@qq.com‘).hexdigest().upper()) === 1D289B39ECB32B5E3DC4A7463E20D030
* choice(string.letters) for i in range(8) 类似于for(i=0;i<8;i++) {random.choice(string.letters)}
* >>> create_user_no(‘451314789@qq.com‘)
‘1D289B39ECB32B5E3DC4A7463E20D030ZdPsLmNo‘
>>> print (hashlib.md5(‘451314789@qq.com‘).hexdigest().upper())
1D289B39ECB32B5E3DC4A7463E20D030
*/
String包介绍:
- >>> import string
- >>> string.digits
- ‘0123456789‘
- >>> string.hexdigits
- ‘0123456789abcdefABCDEF‘
- >>> string.octdigits
- ‘01234567‘
- >>> string.letters
- ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ‘
- >>> string.lowercase
- ‘abcdefghijklmnopqrstuvwxyz‘
- >>> string.uppercase
- ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ‘
- >>> string.printable
- ‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\‘()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c‘
- >>> string.punctuation
- ‘!"#$%&\‘()*+,-./:;<=>?@[\\]^_`{|}~‘
- >>> string.whitespace
- ‘\t\n\x0b\x0c\r ‘
- >>>
- string.atof(s)将字符串转为浮点型数字
- >>> string.atof("1.23")
- 1.23
- >>> string.atof("1")
- 1.0
string.atoi(s,[base=num])将字符串转为整型数字,base 指定进制- >>> string.atoi("20")
- 20
- >>> string.atoi("20",base=10)
- 20
- >>> string.atoi("20",base=16)
- 32
- >>> string.atoi("20",base=8)
- 16
- >>> string.atoi("20",base=2)
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "/usr/lib64/python2.6/string.py", line 403, in atoi
- return _int(s, base)
- ValueError: invalid literal for int() with base 2: ‘20‘
- >>> string.atoi("101",base=2)
- 5
- >>> string.atoi("101",base=6)
- 37
string.capwords(s,sep=None)以sep作为分隔符,分割字符串s,然后将每个字段的首字母换成大写- >>> string.capwords("this is a dog")
- ‘This Is A Dog‘
- >>> string.capwords("this is a dog",sep=" ")
- ‘This Is A Dog‘
- >>> string.capwords("this is a dog",sep="s")
- ‘This is a dog‘
- >>> string.capwords("this is a dog",sep="o")
- ‘This is a doG‘
- >>>
string.maketrans(s,r)创建一个s到r的转换表,然后可以使用translate()方法来使用- >>> replist=string.maketrans("123","abc")
- >>> replist1=string.maketrans("456","xyz")
- >>> s="123456789"
- >>> s.translate(replist)
- ‘abc456789‘
- >>> s.translate(replist1)
- ‘123xyz789‘
- >>> string.atof("1.23")