变量正在更改内部的值。。。环

2024-06-26 13:51:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一段代码:

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

我不明白为什么会这样。我的代码也有其他组件,所以我可以解释如果你需要任何细节。谢谢


Tags: to代码tokenifmodetimestampwritestr