【问题标题】:Escape quote in python os.system("command")python os.system("command") 中的转义引号
【发布时间】:2019-01-20 19:01:58
【问题描述】:

我想通过 os.system(command) 运行以下命令

echo '@include("acf/rows.php")' >>  ../functions.php

我似乎无法正确转义引号。我该怎么做?

【问题讨论】:

  • os.system('echo \'@include(\"acf/rows.php\")\' >> ../functions.php')?
  • 您的os.system() 尝试在哪里?
  • 请向我们提供您的代码,以便我们重现您的错误。
  • @Tomothy32:OP 想用 python 使用os
  • 为什么不使用 Python 文件函数而不是这种双重间接方法附加到文件...?!

标签: python escaping os.system


【解决方案1】:
os.system('echo \'@include(\"acf/rows.php\")\' >> ../functions.php')

非常感谢@Tomothy32

更好:

with open("../functions.php", "a") as functions:
        functions.write("@import('acf/rows.php');")

感谢@deceze

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-08
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 2012-10-05
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    相关资源
    最近更新 更多