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

    <legend id='YqXTG'><style id='YqXTG'><dir id='YqXTG'><q id='YqXTG'></q></dir></style></legend>

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

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

      1. 使用 pickle.dump - TypeError: must be str, not bytes

        Using pickle.dump - TypeError: must be str, not bytes(使用 pickle.dump - TypeError: must be str, not bytes)

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

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

                • <legend id='R7pv9'><style id='R7pv9'><dir id='R7pv9'><q id='R7pv9'></q></dir></style></legend>
                  本文介绍了使用 pickle.dump - TypeError: must be str, not bytes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用的是 python3.3,在尝试腌制一个简单的字典时遇到了一个神秘的错误.

                  I'm using python3.3 and I'm having a cryptic error when trying to pickle a simple dictionary.

                  代码如下:

                  import os
                  import pickle
                  from pickle import *
                  os.chdir('c:/Python26/progfiles/')
                  
                  def storvars(vdict):      
                      f = open('varstor.txt','w')
                      pickle.dump(vdict,f,)
                      f.close()
                      return
                  
                  mydict = {'name':'john','gender':'male','age':'45'}
                  storvars(mydict)
                  

                  我得到:

                  Traceback (most recent call last):
                    File "C:/Python26/test18.py", line 31, in <module>
                      storvars(mydict)
                    File "C:/Python26/test18.py", line 14, in storvars
                      pickle.dump(vdict,f,)
                  TypeError: must be str, not bytes
                  

                  推荐答案

                  输出文件需要以二进制方式打开:

                  The output file needs to be opened in binary mode:

                  f = open('varstor.txt','w')
                  

                  需要:

                  f = open('varstor.txt','wb')
                  

                  这篇关于使用 pickle.dump - TypeError: must be str, not bytes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)
                      <tbody id='i2m10'></tbody>

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

                        <legend id='i2m10'><style id='i2m10'><dir id='i2m10'><q id='i2m10'></q></dir></style></legend>

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

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