下面的代码不起作用,数据是字典&我想知道如何将它传递给函数
from google.cloud import pubsub;
subscriber = pubsub.SubscriberClient()
subscription_path = subscriber.subscription_path(<project_id>,
<subscription_name>)
def callback(message):
print(message.data)
subscriber.subscribe(subscription_path, callback=callback)
答案 0 :(得分:2)
以下代码应该适合您:
def my_function(x={}):
for i, j in x.iteritems():
print (i)
print (j)
data = {'a':1, 'b': 2, 'c': 3}
my_function(data)
<强>解释强>
dict.iteritems
(在Python 2.x中)或dict.items
(在Python 3中)。**
运算符。