0

你好我正在使用带有firebase的python,但我无法正确执行下面的代码。我想要'data.Child('move')。get() ' 只是为了价值,但是当我运行程序时,我会得到以下 'Ordereddict([( 'move', True)]) 并且我希望你只给我 True。有人可以帮助我

import pyrebase
config = {
  "apiKey": "...",
  "authDomain": "...",
  "databaseURL": "...",
  "projectId": "...",
  "storageBucket": "...",
  "messagingSenderId": "...",
  "appId": "...",
  "measurementId": "..."
};
firebase = pyrebase.initialize_app(config)
dados = firebase.database()
users = dados.child('mover').get()
mov = users.val()
print(mov)
if mov == 'True':
  print('true')
elif mov == 'False':
  print('false')
4

1 回答 1

1

您正在寻找的是value, 使其更加水晶:

from collections import OrderedDict

# creating a simple dict
my_dict = {'move': True}

# creating ordered dict from dict
ordered_dict = OrderedDict(my_dict)

for k,v in ordered_dict.items():
    print(v)

输出:

True

单线:

print(list(ordered_dict.values()))   # [True]

在您的具体情况下:

print(list(mov.values())[0])   # True
于 2020-06-17T17:48:51.193 回答