python - 我收到此错误“NoneType”对象没有属性“组”
问题描述
import re
import subprocess
def get_speaker_output_volume():
cmd = "osascript -e 'get volume settings'"
process = subprocess.run(cmd, stdout=subprocess.PIPE, shell=True)
output = process.stdout.strip().decode('ascii')
pattern = re.compile(r"output volume:(\d+), input volume:(\d+), "
r"alert volume:(\d+), output muted:(true|false)")
volume, _, _, muted = pattern.match(output).groups()
volume = int(volume)
muted = (muted == 'true')
print("Volume: ",volume)
if muted==1:
print("Volme is muted.")
else:
print("Volume is not muted.")
get_speaker_output_volume()
音量,_,_,静音 = pattern.match(output).groups()
AttributeError: 'NoneType' 对象没有属性 'groups'
解决方案
推荐阅读
- python - 矩阵变换的嵌套列表
- c# - 使用 c# SmtpClient 的 Gmail SMTP 失败
- android - Firebase 数据库 - 为数据库中的用户设置规则
- html - 在 flexbox 的情况下,内联元素锚标记尊重顶部和底部的填充,为什么?
- python - 使用 OpenCV Python 创建新的相机源(Camera Driver Using Python)
- migration - 大型机迁移到 USS/Github
- java - 将数据插入 mysql 表时出现“java.lang.NullPointerException”错误
- angular - NGRX 效果无限循环
- machine-learning - 为什么我在同一张图片上得到了 2 个不同的特征图和相同的内核?
- excel - 从打开的文本字段中过滤电话号码 - Power BI、excel、VBA