繁体   English   中英

如何从python脚本内部运行一个url到命令行?

[英]How to run a url from inside a python script to command line?

我有这个命令行文本,我想在我的 python 脚本中运行到命令行。 关于如何做到这一点的任何建议?

explorer "ms-drive-to:? 



destination.latitude=47.680504&destination.longitude=-122.328262&destination.name=Green Lake"

当然,你可以做类似这篇文章中描述的事情:

https://raspberrypi.stackexchange.com/questions/17017/how-do-i-run-a-command-line-command-in-a-python-script

似乎您应该使用subprocess

在 Python 中运行 Bash 命令

如果你想在 python shell 中有效地运行它,像这样:# it will open windows map

>>> !explorer "ms-drive-to:? 
destination.latitude=47.680504&destination.longitude=-122.328262&destination.name=Green Lake"

如果你想在代码中运行,就像其他方法一样。所有答案都是正确的。

import os

command_str = 'explorer "ms-drive-to:? destination.latitude=47.680504&destination.longitude=-122.328262&destination.name=Green Lake"'
os.system(command_str)
# it will open windows map, and driving directions to Green Lake from your current location.

小心使用双引号,单引号将无法正确识别! 结果

windows uwp 信息: https ://docs.microsoft.com/en-us/windows/uwp/launch-resume/launch-maps-app

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM