是"shadows name from outer scopes an error"?

Is "shadows name from outer scopes an error"?

你好,我正在编写一个 Python 代码,我收到了两个用绿色下划线标有 "Shadows name 'value' from outer scope" 和 "Shadows name 'value1' from outer scope" 的变量。这是一个错误吗?我该如何解决这个问题?我的代码应该从 firebase 实时数据库中读取两个变量数据。如果两个变量数据都是 1,那么我应该在 phone 上收到通知。代码有错吗? 请注意,它工作正常,我能够收到通知,但是当我添加第二个变量并修改代码时,我无法再收到通知。

value = 0
value1 = 0


def stream_handler(message):
    print(message)
    if message['data'] is 1:
        value = 1 //here the variable is underlined in green
        value = value //here the variable is underlined in green
        return value


def stream_handler1(message1):
    print(message1)
    if message1['data'] is 1:
        value1 = 1 //here the variable is underlined in green
        value1 = value1 //here the variable is underlined in green
        return value1


if value is 1 & value1 is 1:

            response = pn_client.publish(
             interests=['hello'],
             publish_body={
                 'apns': {
                     'aps': {
                         'alert': 'Hello!',
                     },
                 },
                 'fcm': {
                    'notification': {
                      'title': 'Notification',
                      'body': 'Fall Detected !!',
                     },
                  },
             },
            )

            print(response['publishId'])


my_stream = db.child("Fall_Detection_Status").stream(stream_handler)
my_stream1 = db.child("Fall_Detection_Status1").stream(stream_handler1)

你可能是这个意思:

def stream_handler(message):
    global value
    print(message)
    # rest of function elided


def stream_handler1(message1):
    global value1
    print(message1)
    # rest of function elided

global 语句告诉 Python 您的意思是使用值变量的全局版本而不是本地版本。

此外,您可能不希望这样的语句:

value = value

因为这没有任何意义。