推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
Dragonish3600
V2EX  ›  Python

初学 Python ,请问这段代码的含义。。return base64.b64decode(s+b'==')

  •  
  •   Dragonish3600 · Oct 19, 2018 · 4546 views
    This topic created in 2944 days ago, the information mentioned may be changed or developed.

    def safe_base64_decode(s): return base64.b64decode(s+b'==')

    看廖雪峰教程上有人发的 这是传入 s,然后把 s 去掉== 传出然后返回么? python 这个语法感觉好怪。。

    6 replies  •  2018-10-19 18:36:56 +08:00
    locoz
    locoz
    Oct 19, 2018
    1
    这不就是把 s 变量加上两个等于号然后 base64decode 吗。。
    Dragonish3600
    Dragonish3600
    OP
    Oct 19, 2018
    2
    @locoz 突然发现这语句是 decode 不是 encode。。。。脑残了。。
    NoAnyLove
    NoAnyLove
    Oct 19, 2018
    3
    s+b = sb?

    这里的 b 是 bytes 前缀,代表 bytes 的字符串,也就是说,应该看成 s + b'=='。所以,你要抑制住把 s 和 b 连在一起看的冲动啊。(手动滑稽)
    choury
    choury
    Oct 19, 2018 via Android
    4
    =是 base64 里的占位符,这个代码就是不想算后面需要几个占位符,无脑加两个吧
    sideman
    sideman
    Oct 19, 2018 via Android
    5
    base64 码用=补位,不过一般用 4-len(s)%4
    确定补位的个数
    lenov0
    lenov0
    Oct 19, 2018
    6
    这不是在用 base64 加密吗
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4232 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 542ms · UTC 07:47 · PVG 15:47 · LAX 23:47 · JFK 02:47
    ♥ Do have faith in what you're doing.