【问题标题】:Python - How to save lines from python36 command line to a .py file?Python - 如何将 python36 命令行中的行保存到 .py 文件中?
【发布时间】:2018-03-02 01:02:51
【问题描述】:

python 有一个类似 CMD 的工具,python36。 如果您键入一行并按回车键,您将获得输出。 我想将我在那里写的任何内容保存到一个以 .py 结尾的文件中,我该怎么做? 谢谢。

【问题讨论】:

  • 复制和意大利面?

标签: python file save


【解决方案1】:

一个简单的演示代码:

with open("output.py","w") as fp:
    while True:
        line = input("please input:")
        if line == "": # press enter to exit
            break
        fp.write(line+"\n")

【讨论】:

    猜你喜欢
    • 2020-03-09
    • 1970-01-01
    • 1970-01-01
    • 2011-08-15
    • 2021-02-01
    • 1970-01-01
    • 2018-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多