LINUX.ORG.RU

Значение переменной не восстанавливается

 


0

1
functions={
    'metran-910': ['port_address','port_baudrate','bus_address','function','register_start','register_count'],
    }
    
def get_queue(device, function):
    print function
    devices = Device.objects.filter(type=device,interview=True)
    for device in devices:
        for field,value in device.__dict__.items():
            if field in function:
                index=function.index(field)
                del function[index]
                function.insert(index,value)
                
def start_get_queue():
    for device,function in functions.items():
        get_queue(device,function)

При первом вызове:

>>> start_get_queue()
['port_address', 'port_baudrate', 'bus_address', 'function', 'register_start', 'register_count']

При втором и последующих вызове список function уже хранит значение:

>>> start_get_queue()
[14L, 115200L, 1L, 'function', 'register_start', 'register_count']

Как лечить?


Значение переменной не восстанавливается

Не вижу, почему бы ему восстанавливаться.

tailgunner ★★★★★
()

Не знаю, что там у вас в БД, но вот эта строчка «if field in function:», по-моему должна звучать так: «if field in function['metran-910']:»

k0valenk0_igor ★★★
()
index=function.index(field)
del function[index]
function.insert(index,value)

С вероятностью близкой к 146% тебе нужен словарь.

zz ★★★★
()

Есть модуль copy. Лечи им

Leron ★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.