我有来自api的天气(json)数据。我只想显示我放在字典里的一部分:
vals = {
'temperature': 34.41,
'summary': 'Clear',
'ozone': 249.95,
'humidity': 0.32,
'precipType': 'rain',
'pressure': 1010.05,
'dewPoint': 15.31,
'time': 1456393033,
'windSpeed': 2.5,
'apparentTemperature': 34.23,
'icon': 'clear-day',
'windBearing': 96,
'precipProbability': 0.01,
'cloudCover': 0.17,
'precipIntensity': 0.0203
}
我使用此代码以'key:value'的格式显示通知。代码如下:
^{pr2}$输出显示一个通知,标题为(在本例中,摘要为“清除”)和第一个键:值对i、 e.仪器温度:34.23,则终端显示以下错误:
sh: 2: cloudCover: 0.17: not found
sh: 3: dewPoint: 15.31: not found
sh: 4: humidity: 0.32: not found
sh: 5: icon: clear-day: not found
sh: 6: ozone: 249.95: not found
sh: 7: precipIntensity: 0.0203: not found
sh: 8: precipProbability: 0.01: not found
sh: 9: precipType: rain: not found
sh: 10: pressure: 1010.05: not found
sh: 11: temperature: 34.41: not found
sh: 12: time: 2016-02-25: not found
sh: 13: windBearing: 96: not found
sh: 14: windSpeed: 2.5: not found
什么是错误?我如何纠正它?在
错误在}是{}执行的命令。发生这种情况是因为
msg = 'notify-send -u critical ' + vals['summary'] + ' ' + msg
。您的sh
认为参数vals['summary']
和{msg
的输出中有空格(我并没有告诉你与你的msg
-变量同名相关的混淆)。在您可以在输出数据中使用引号(
\"
)来避免它。所以msg
看起来像或者
^{pr2}$升级版 我不明白之前的主要问题,所以:
在脚本中使用多行
notify-send
时出现一些问题。我认为,最简单的方法是在脚本中使用echo -e
,例如:您可以尝试在脚本中使用这种思想,但您必须使用引号和控制字符执行一些技巧。在
相关问题 更多 >
编程相关推荐