首页 > 解决方案 > 我收到此错误“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

解决方案


推荐阅读