【问题标题】:Use output from one python file as input in another使用一个 python 文件的输出作为另一个文件的输入
【发布时间】:2019-07-23 15:55:38
【问题描述】:

我有一个 python 程序,它的文件夹包含在操作数据中具有单独角色的脚本。我希望能够使用运行的最后一个脚本的输出从根目录中的“主”文件中指定这些脚本的输入。

例如。 python3 script2.py -i 输入文件

其中 inputFile 由先前脚本写入的文件描述。比如说,script1.py。

主脚本如下所示:

os.system("python3 subdir1/script1.py -c subdir1/config.json")
os.system("python3 subdir2/script2.py -c subdir2/config.json -i inputFile")

我在 ubuntu 16.04 中使用 wsl。

但我不知道如何将文件名返回到根目录中的主脚本。我只能得到脚本在退出时返回的错误代码。

【问题讨论】:

  • 这里真正的问题是,哪个操作系统?另外,请提供代码,否则我们无法为您提供真正的帮助。
  • 有很多方法可以完成你想做的事情,但这取决于你到底想做什么。两个 python 下标和一个运行它们的 python 脚本?或者在它们之上有一个 bash 脚本?呃,甚至可能是 Windows 上的 .bat 脚本?

标签: python-3.x file-io arguments return-value


【解决方案1】:

我找到了解决方案/解决方法。我使用脚本创建了一个存储文件名的 JSON 文件。然后我在下一个脚本中阅读了它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    • 2020-08-27
    • 1970-01-01
    相关资源
    最近更新 更多