Discuss / Python / 模仿各位大神,练习练习

模仿各位大神,练习练习

Topic source
# -*- coding: utf-8 -*-
#base64_x.py
import base64
def safe_base64_decode(s):
    try:
        s1 = s+b'='*((-len(s))%4)
        return base64.b64decode(s1)
    except:
        s2 = s+'='*((-len(s))%4)
        return base64.b64decode(s2)

#assert使用 若前一句判断false则抛出后面自定义的语句,若没有错误,则什么都不做.    
assert b'abcd' == safe_base64_decode(b'YWJjZA=='), safe_base64_decode('YWJjZA==')
assert b'abcd' == safe_base64_decode(b'YWJjZA=='), safe_base64_decode('YWJjZA==')

print('Pass')

  • 1

Reply