【问题标题】:Converting Linux style substitutions to Windows style substitutions in Python在 Python 中将 Linux 样式替换转换为 Windows 样式替换
【发布时间】:2015-10-25 21:12:05
【问题描述】:

有没有办法将 Linux 样式的 shell 替换转换为 Python 中的 Windows 替换?

假设在 Linux 环境中有一个命令:

my_command=cd
${my_command} .. OR $my_command .. resolves to cd ..

在 Windows 中:

SET my_command=cd
%my_command% .. resolves to cd ..

我想要它,如果我的环境是 Windows,那么我可以接收一个命令并将其替换为 Windows 样式替换:

示例输入/输出:

input: python myscript.py "${my_command}
output: "%my_command%"

谢谢!

【问题讨论】:

    标签: python linux variable-substitution


    【解决方案1】:
    for x in sys.argv:
        if x.startswith("$"):
           print "%%%s%%"%(x[1:])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      • 2018-03-06
      • 2017-03-13
      • 2016-12-09
      • 1970-01-01
      • 2016-06-01
      • 2011-03-08
      相关资源
      最近更新 更多