2024-04-19 10:10:55 发布
网友
我看到here我可以从批处理文件调用python脚本。你知道吗
我想做的是调用python行而不使用脚本。你知道吗
这是我想做的一个例子:
>> echo 'python.exe ''' "this/is/a/path".replace('/','\\')''' '
将返回"this\\is\\a\\path"
"this\\is\\a\\path"
注意:在我的示例中,有一种更简单的方法来做我想做的事情,比如here,但这不是问题:)
多亏了@E.Serra的方法,这一切都会成功的。你知道吗
echo print("this/is/a/path".replace("/","\\")) > tmp_file && python tmp_file && rm tmp_file
>
C:\Python27>echo print("this/is/a/path".replace("/","\\")) >tmp_python_File && python tmp_python_File && rm tmp_python_File this\is\a\path
您可以使用-c标志:
-c
Specify the command to execute (see next section). This terminates the option list (following options are passed as arguments to the command).
python -c '''print("this/is/a/path".replace("/","\\"))''' > this\is\a\path
好吧,如果你只是试着运行你的python.exe然后:
python python.exe
如果您想运行perl风格的oneliners,那么:
echo '''print("this/is/a/path".replace("/","\\"))''' >tmp_python_File && python tmp_python_File && rm tmp_python_File
吐口水:
$>;这是一条路径
多亏了@E.Serra的方法,这一切都会成功的。你知道吗
>
您可以使用
-c
标志:好吧,如果你只是试着运行你的python.exe然后:
如果您想运行perl风格的oneliners,那么:
吐口水:
$>;这是一条路径
相关问题 更多 >
编程相关推荐