【问题标题】:How do I do a Py3k pickle dump?如何进行 Py3k 泡菜转储?
【发布时间】:2013-05-06 20:47:42
【问题描述】:

我通过 cgitb 收到以下错误:

TypeError: must be str, not bytes 
      args = ('must be str, not bytes',) 
      with_traceback = <built-in method with_traceback of TypeError object>

单挑出来的代码行是:

pickle.dump(state, output_file)

输出文件打开到特定路径进行写入。

我认为我没有见过 Py3k 以新方式创建、编组和解组“hello world”字符串的“hello pickle”。任何人都愿意解释我需要对文件做哪些不同的处理(指定 UTF-8 编码或其他内容),并发布从 Py3k 的基本字符串编组和解组的“Hello world”?

【问题讨论】:

    标签: python python-3.x marshalling pickle utf


    【解决方案1】:

    如果您以wr 模式打开文件,请将其更改为wb,它应该可以工作。基本上,以二进制模式打开它。

    【讨论】:

    • 谢谢!这就是我所缺少的。
    猜你喜欢
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 2018-06-13
    • 1970-01-01
    • 2022-07-16
    • 2023-03-25
    • 2019-08-10
    相关资源
    最近更新 更多