【问题标题】:How to add my "print content" into a text file [duplicate]如何将我的“打印内容”添加到文本文件中[重复]
【发布时间】:2021-08-14 00:00:37
【问题描述】:

最近开始学习 Python。

我定义了标题和价格。

现在我想让 Python 创建一个文本文件,并将“标题”和“价格”的内容输入到新创建的文本文件中

print(title)
print(price)

fh = open("Price&Title", "w")
fh.write()
fh.close()

上面的这段代码没有用。

【问题讨论】:

    标签: python python-3.x


    【解决方案1】:

    您可以使用printfile 参数:

    fh = open("Price&Title", "w")
    print(title, file=fh)
    print(price, file=fh)
    fh.close()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-04
      • 2013-08-19
      • 1970-01-01
      • 1970-01-01
      • 2013-10-28
      • 2021-12-10
      • 2016-02-08
      • 2021-08-02
      相关资源
      最近更新 更多