簡體   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