【问题标题】:How to store the generated txt file in the BinaryField如何将生成的txt文件存储在BinaryField中
【发布时间】:2018-02-13 06:19:06
【问题描述】:
file = open("text1.txt", 'w')
file.write("Hello World")
file.close()

我有一个二进制字段,即 storetext

storetext= fields.Binary(string='Text File')

如何将 txt 文件存储在 storetext 字段中?

【问题讨论】:

  • 什么storetext字段?请阅读minimal reproducible example
  • @wwii 是一开始我指出storetext,对不起,我现在编辑了它
  • 我知道的fields 模块没有Binary 类。您能否提供指向该模块文档的链接?
  • 你试过BinaryField而不是Binary..?

标签: python file text store


【解决方案1】:

你在找这个吗?

with open('text1.txt') as fin:
    storetext = fields.Binary(fin.read())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-02
    • 1970-01-01
    • 1970-01-01
    • 2012-09-19
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 2021-02-09
    相关资源
    最近更新 更多