【发布时间】:2017-08-28 16:16:46
【问题描述】:
我尝试使用 os.system 在 chromium 中打开一个 url,将 GET 参数传递给 php 页面。然而,铬似乎不接受或承认不止一个论点。
url = "chromium-browser localhost/index.php?temp=" + str(int(math.floor(get_temperature()))) + "&id=" + get_id()
print(url)
os.system(url)
正在打印的字符串: 铬浏览器 localhost/index.php?temp=15&id=10
正在打开的网址: http://localhost/index.php?temp=15
已解决
将 URL 用引号括起来解决了这个问题。
【问题讨论】:
-
如果您在操作系统的命令行中键入
chromium-browser localhost/index.php?temp=15&id=10,会发生什么? (提示:您可能想尝试将参数用引号括起来) -
谢谢,解决问题
-
我推荐使用
{}.format 样式而不是使用+来连接:url = "chromium-browser localhost/index.php?temp={}&id={}".format(math.floor(get_temperature()), get_id())——它会将所有类型强制转换为字符串,因此您不必包装参数.