0
number = droid.readPhoneState()['result']['incomingNumber']

What are 'result' and 'incomingNumber' in this syntax -- are they not parameters?

How are they related to the function readPhoneState?

import android

droid = android.Android()
droid.startTrackingPhoneState()

number = droid.readPhoneState()['result']['incomingNumber']

if number != None:
  droid.speak('Call from '+str(number))
else:
  droid.makeToast('No incoming call')
Katriel
  • 120,462
  • 19
  • 136
  • 170
Tiwari
  • 1,014
  • 2
  • 12
  • 22

5 Answers5

9

droid.readPhoneState() returns a dict of dicts. Equivalent code:

outerDict = droid.readPhoneState()
innerDict = outerDict['result']
number = innerDict['incomingNumber']
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
2

result and incomingNumber are keys to a dictionary or an instance of a class that implements method __getitem__. This means that readPhoneState() returns a dictionary object, which supposed to have a key result and the corresponding value is a dictionary object which supposed to have a key incomingNumber.

khachik
  • 28,112
  • 9
  • 59
  • 94
1

the interpretation is that droid.readPhoneState() returns a dict, whose value corresponding to the key 'result' is another dict.

lijie
  • 4,811
  • 22
  • 26
1

readPhoneState() is the method and it returns a dictionary object.

The dictionary object contains the property result which is also a dictionary object containing the property incomingNumber

John Giotta
  • 16,432
  • 7
  • 52
  • 82
0

Supposedly, readPhoneState() returns a dictionary where values are, again, dictionaries.

With this syntax, you get the dictionary - returned by readPhoneState() - associated with key 'result' and ask it for the value whose key is 'incomingNumber'.

Simone
  • 11,655
  • 1
  • 30
  • 43