<i id='DLdpZ'><tr id='DLdpZ'><dt id='DLdpZ'><q id='DLdpZ'><span id='DLdpZ'><b id='DLdpZ'><form id='DLdpZ'><ins id='DLdpZ'></ins><ul id='DLdpZ'></ul><sub id='DLdpZ'></sub></form><legend id='DLdpZ'></legend><bdo id='DLdpZ'><pre id='DLdpZ'><center id='DLdpZ'></center></pre></bdo></b><th id='DLdpZ'></th></span></q></dt></tr></i><div id='DLdpZ'><tfoot id='DLdpZ'></tfoot><dl id='DLdpZ'><fieldset id='DLdpZ'></fieldset></dl></div>

        <bdo id='DLdpZ'></bdo><ul id='DLdpZ'></ul>
      <tfoot id='DLdpZ'></tfoot>

      <small id='DLdpZ'></small><noframes id='DLdpZ'>

    1. <legend id='DLdpZ'><style id='DLdpZ'><dir id='DLdpZ'><q id='DLdpZ'></q></dir></style></legend>

      将 ascii 字符串转换为 base64,不带“b";和引号

      时间:2023-09-29

    2. <legend id='ynsfP'><style id='ynsfP'><dir id='ynsfP'><q id='ynsfP'></q></dir></style></legend>

      <small id='ynsfP'></small><noframes id='ynsfP'>

          <tfoot id='ynsfP'></tfoot>

              <tbody id='ynsfP'></tbody>

              <i id='ynsfP'><tr id='ynsfP'><dt id='ynsfP'><q id='ynsfP'><span id='ynsfP'><b id='ynsfP'><form id='ynsfP'><ins id='ynsfP'></ins><ul id='ynsfP'></ul><sub id='ynsfP'></sub></form><legend id='ynsfP'></legend><bdo id='ynsfP'><pre id='ynsfP'><center id='ynsfP'></center></pre></bdo></b><th id='ynsfP'></th></span></q></dt></tr></i><div id='ynsfP'><tfoot id='ynsfP'></tfoot><dl id='ynsfP'><fieldset id='ynsfP'></fieldset></dl></div>

              • <bdo id='ynsfP'></bdo><ul id='ynsfP'></ul>
                本文介绍了将 ascii 字符串转换为 base64,不带“b";和引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想将一个 ascii 字符串(准确地说是文本)转换为 base64.所以我知道该怎么做,我只使用以下代码:

                I wanted to convert an ascii string (well just text to be precise) towards base64. So I know how to do that, I just use the following code:

                import base64
                string = base64.b64encode(bytes("string", 'utf-8'))
                print (string)
                

                这给了我

                b'c3RyaW5n'
                

                但问题是,我希望它只打印

                However the problem is, I'd like it to just print

                c3RyaW5n
                

                是否可以打印没有 "b" 和 '' 引号的字符串?谢谢!

                Is it possible to print the string without the "b" and the '' quotation marks? Thanks!

                推荐答案

                b 前缀表示它是一个二进制字符串.二进制字符串不是字符串:它是一个字节序列(值在 0 到 255 范围内).它被简单地排版为字符串以使其更紧凑.

                The b prefix denotes that it is a binary string. A binary string is not a string: it is a sequence of bytes (values in the 0 to 255 range). It is simply typesetted as a string to make it more compact.

                然而,在 base64 的情况下,所有字符都是有效的 ASCII 字符,因此您可以像这样简单地对其进行解码:

                In case of base64 however, all characters are valid ASCII characters, you can thus simply decode it like:

                print(string.decode('ascii'))
                

                因此,我们将在这里将每个字节解码为其 ASCII 等价物.由于 base64 保证它产生的每个字节都在 'A''/' 的 ASCII 范围内,因此我们将始终产生一个有效的字符串.但是请注意,这是 用任意二进制字符串保证的.

                So here we will decode each byte to its ASCII equivalent. Since base64 guarantees that every byte it produces is in the ASCII range 'A' to '/') we will always produce a valid string. Mind however that this is not guaranteed with an arbitrary binary string.

                这篇关于将 ascii 字符串转换为 base64,不带“b";和引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Base64 字符串到 tkinter 中的图像 下一篇:如何在函数之间传递编辑的wav而不在两者之间保存wav?

                相关文章

                <tfoot id='cGRM0'></tfoot>

                  • <bdo id='cGRM0'></bdo><ul id='cGRM0'></ul>

                  <small id='cGRM0'></small><noframes id='cGRM0'>

                  <i id='cGRM0'><tr id='cGRM0'><dt id='cGRM0'><q id='cGRM0'><span id='cGRM0'><b id='cGRM0'><form id='cGRM0'><ins id='cGRM0'></ins><ul id='cGRM0'></ul><sub id='cGRM0'></sub></form><legend id='cGRM0'></legend><bdo id='cGRM0'><pre id='cGRM0'><center id='cGRM0'></center></pre></bdo></b><th id='cGRM0'></th></span></q></dt></tr></i><div id='cGRM0'><tfoot id='cGRM0'></tfoot><dl id='cGRM0'><fieldset id='cGRM0'></fieldset></dl></div>

                1. <legend id='cGRM0'><style id='cGRM0'><dir id='cGRM0'><q id='cGRM0'></q></dir></style></legend>