1

我正在尝试将类字典分配为值,将字符串分配为键。在主循环中打印它们时我有正确的值,但是一旦我离开主循环,我的“cliStat”变量就会出现刚刚用“O”值初始化..

这是我进行分配和打印的代码部分。我的问题是,为什么 cliStat 保持“0”值?

cliStat = {}
for org in client:

        cliStat[ org ] = StatEntry( org, "0", "0", "0", "0", "0", "0", "0" ) 


self.getFilteredStat( client, date_debut, date_fin )

for statEntry in self.tabStatEntry.values():

        cliStat[ statEntry.client ].nb_users += statEntry.nb_users
        cliStat[ statEntry.client ].nb_pages = ( statEntry.nb_pages + cliStat[ statEntry.client ].nb_pages ) / 2
        cliStat[ statEntry.client ].perf_rate = ( statEntry.perf_rate + cliStat[ statEntry.client ].perf_rate ) / 2
        cliStat[ statEntry.client ].response_time = ( statEntry.response_time + cliStat[ statEntry.client ].response_time ) / 2
        cliStat[ statEntry.client ].nb_errors = ( statEntry.nb_errors + cliStat[ statEntry.client ].nb_errors ) / 2
        cliStat[ statEntry.client ].perf_globale = ( statEntry.perf_globale + cliStat[ statEntry.client ].perf_globale ) / 2
        cliStat[ statEntry.client ].perf_server = ( statEntry.perf_server + cliStat[ statEntry.client ].perf_server ) / 2
        cliStat[ statEntry.client ].perf_network = ( statEntry.perf_network + cliStat[ statEntry.client ].perf_network ) / 2
        cliStat[ statEntry.client ].perf_redirect = ( statEntry.perf_redirect + cliStat[ statEntry.client ].perf_redirect ) / 2


for cle,val in cliStat.items():

        print val

如果需要,这是完整的代码;http://dpaste.com/914508/

如果需要运行代码,这里是数据文件http://rapidshare.com/files/2185155450/meteo.7z

只需使用您的文件夹更改 logDir 变量。

谢谢你看看!

4

1 回答 1

0

并非所有对象都保持填充零。

我将最后一个循环更改为

    for cle,val in cliStat.items():
        if val.nb_users:
            print val

并得到六个客户端的输出,所有客户端都填充了非零数据。

最好先用少量数据测试代码。

于 2013-02-08T11:14:11.787 回答