Python Forum
Dictionary value not recognized
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary value not recognized
#1
Im fetching data from firebase like this:

#imports....
class AIHome:

def __init__(self, onTime, offTime):
#init stuff

def fetchUpdate(self):
AIHome.authentication = firebase.FirebaseAuthentication('mykey', 'myemail', extra={'id': 123})
AIHome.firebase = firebase.FirebaseApplication('https://myapp.firebaseio.com/', AIHome.authentication)
print AIHome.authentication.extra

AIHome.user = AIHome.authentication.get_user()
print AIHome.user.firebase_auth_token

AIHome.results = AIHome.firebase.get('/Relays', None)#, {'print': 'pretty'})
print AIHome.results
print AIHome.results.Relay1ON #when i try to use it here it fails!!!!!
print AIHome.results.Relay1OFF

self.relayToggle()
it returns this:


{u'Relay1ON': 1800, u'Relay1OFF': u'0600'}
so when I try to use the dict and read its value I get this:

File "tsrb430.py", line 54, in fetchUpdate
    print AIHome.results.Relay1ON
AttributeError: 'dict' object has no attribute 'Relay1ON'
Please help
Reply
#2
Indentation is wrong in first code.

You can not do a dot'ed call on a dictionary.
>>> results = {u'Relay1ON': 1800, u'Relay1OFF': u'0600'}
>>> results.Relay1ON
Traceback (most recent call last):
 File "<string>", line 301, in runcode
 File "<interactive input>", line 1, in <module>
AttributeError: 'dict' object has no attribute 'Relay1ON'

>>> results['Relay1ON']
1800
>>> #Or get()
>>> results.get('Relay1ON', 'Not here')
1800
>>> results = {u'Relay1ON999': 1800, u'Relay1OFF': u'0600'}
>>> results.get('Relay1ON', 'Not here')
'Not here'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  is import cointegration_analysis a recognized module mitcht33 1 425 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  The term 'pip' is not recognized as the name of a cmdlet, function michaelnicol 1 626 Jul-16-2023, 11:12 PM
Last Post: deanhystad
  Index Function not recognized in Python 3 Peter_B_23 1 1,205 Jan-08-2023, 04:52 AM
Last Post: deanhystad
  TypeError: size; expecting a recognized type filling string dict a11_m11 0 2,518 Feb-10-2020, 08:26 AM
Last Post: a11_m11
  matplotlib isn't recognized after installation Pavel_47 5 2,813 Sep-18-2019, 07:01 PM
Last Post: snippsat
  how do i get y to be recognized in this comprehension? Skaperen 5 3,110 Aug-26-2019, 07:43 PM
Last Post: Skaperen
  why is my dictionary not recognized as such zatlas1 5 3,755 Jan-14-2019, 01:15 AM
Last Post: woooee
  pyserial-master installed bbut not recognized elwolv1 0 1,982 Jan-04-2019, 08:37 PM
Last Post: elwolv1
  How do I calculate the smallest value that is recognized as a difference when compari AFoeee 1 2,779 Oct-28-2018, 10:48 PM
Last Post: Gribouillis
  'videodigest' is not recognized as an internal or external command MM2018 2 2,772 Oct-12-2018, 02:43 PM
Last Post: MM2018

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020