python函数调用语法... result = foo() ['abc'] [英] python function call syntax ... result = foo() ['abc']
本文介绍了python函数调用语法... result = foo() ['abc']的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
number = droid.readPhoneState()['result']['incomingNumber']
此语法中的result"和incomingNumber"是什么——它们不是参数吗?
What are 'result' and 'incomingNumber' in this syntax -- are they not parameters?
它们与函数readPhoneState
有什么关系?
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')
推荐答案
droid.readPhoneState()
返回一个字典.等效代码:
droid.readPhoneState()
returns a dict of dicts. Equivalent code:
outerDict = droid.readPhoneState()
innerDict = outerDict['result']
number = innerDict['incomingNumber']
这篇关于python函数调用语法... result = foo() ['abc']的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文