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包介绍:

    1. >>> import string
    2. >>> string.digits
    3. '0123456789'
    4. >>> string.hexdigits
    5. '0123456789abcdefABCDEF'
    6. >>> string.octdigits
    7. '01234567'
    8. >>> string.letters
    9. 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    10. >>> string.lowercase
    11. 'abcdefghijklmnopqrstuvwxyz'
    12. >>> string.uppercase
    13. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    14. >>> string.printable
    15. '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
    16. >>> string.punctuation
    17. '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
    18. >>> string.whitespace
    19. '\t\n\x0b\x0c\r '
    20. >>>
  1.  
    string.atof(s)将字符串转为浮点型数字
      1. >>> string.atof("1.23")
      2. 1.23
      3. >>> string.atof("1")
      4. 1.0
    string.atoi(s,[base=num])将字符串转为整型数字,base 指定进制
      1. >>> string.atoi("20")
      2. 20
      3. >>> string.atoi("20",base=10)
      4. 20
      5. >>> string.atoi("20",base=16)
      6. 32
      7. >>> string.atoi("20",base=8)
      8. 16
      9. >>> string.atoi("20",base=2)
      10. Traceback (most recent call last):
      11. File "<stdin>", line 1, in <module>
      12. File "/usr/lib64/python2.6/string.py", line 403, in atoi
      13. return _int(s, base)
      14. ValueError: invalid literal for int() with base 2: '20'
      15. >>> string.atoi("101",base=2)
      16. 5
      17. >>> string.atoi("101",base=6)
      18. 37
    string.capwords(s,sep=None)以sep作为分隔符,分割字符串s,然后将每个字段的首字母换成大写
     
      1. >>> string.capwords("this is a dog")
      2. 'This Is A Dog'
      3. >>> string.capwords("this is a dog",sep=" ")
      4. 'This Is A Dog'
      5. >>> string.capwords("this is a dog",sep="s")
      6. 'This is a dog'
      7. >>> string.capwords("this is a dog",sep="o")
      8. 'This is a doG'
      9. >>>
    string.maketrans(s,r)创建一个s到r的转换表,然后可以使用translate()方法来使用
     
      1. >>> replist=string.maketrans("123","abc")
      2. >>> replist1=string.maketrans("456","xyz")
      3. >>> s="123456789"
      4. >>> s.translate(replist)
      5. 'abc456789'
      6. >>> s.translate(replist1)
      7. '123xyz789'
上一篇:Python环境配置安装


下一篇:移植X264成功