Twilio Python程序被困(未声明的变量作为函数参数)

时间:2015-01-15 14:49:56

标签: python syntax parameters global-variables twilio

我有以下代码,但它似乎在调试print语句之前卡在Text函数中。我觉得它与我的函数参数如何设置变量有关,但我不确定这样做的正确方法是什么。

from twilio.rest import TwilioRestClient

Initialize(debug=False):
    global Twilio
    Twilio = TwilioRestClient('***', '***')
    global Numbers
    Numbers = {'***':'+***', '***':'+***', '***':'+***'}
    if debug:
        print 'Intialize Debug Enabled'

def Text(message, recipient, debug=False):
    Twilio.messages.create(body=message, to=recipient, from_='+***')
    if debug:
        print 'Text Debug Enabled'

while True:
    Initialize(True)
    Text('***', Numbers['***'], True)

1 个答案:

答案 0 :(得分:0)

试试这个:

from twilio.rest import TwilioRestClient

client = None
Numbers = None

def Initialize(debug=False):
    global client
    client = TwilioRestClient('***', '***')
    global Numbers
    Numbers = {'***':'+***', '***':'+***', '***':'+***'}
    if debug:
        print 'Intialize Debug Enabled'

def Text(message, recipient, debug=False):
    client.messages.create(body=message, to=recipient, from_='+***')
    if debug:
        print 'Text Debug Enabled'

Initialize(True)

for k, v in Numbers.items():
    Text(k, v, True)