gpt4 book ai didi

python - 在 Python 中将 Linux 样式替换转换为 Windows 样式替换

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:42:19 24 4
gpt4 key购买 nike

有没有办法将 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%"

谢谢!

最佳答案

for x in sys.argv:
if x.startswith("$"):
print "%%%s%%"%(x[1:])

关于python - 在 Python 中将 Linux 样式替换转换为 Windows 样式替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31792768/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com