为...循环变量值

时间:2015-11-30 20:14:49

标签: python variables scope

我有这段代码:

if (currstates and useravailable(currstates)):
    thisstates = list(currstates)
    for token in unserved:

        mode, timestamp = modality(token, thisstates)

        to_write = str(timestamp)+' '+str(token[1])+' '+str(token[2])+' '+mode+'\n'
        output.write(to_write)
        unserved.remove(token)

我称之为函数:

def modality(token, herestate):
    #print(herestate)
    if (token[3] == 'high'):
        timest = token[0]
    else:
        timest = herestate[0]
    modal = 'auditory'
    if herestate[2] == 'phone':
        modal = 'visual'
    elif (herestate[3] == 'silent' or herestate[4]=='quiet'):
        modal = 'tactile'
    #print(timest)
    return (modal,timest)

我不明白为什么

thisstates 

变量通过

更改两次迭代之间的值
unserved

我无法理解为什么会这样。我的代码也有其他组件,所以我可以解释你是否需要任何细节。感谢。

0 个答案:

没有答案
相关问题