本文介绍了Bizzare长度问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好...希望我的上一个问题:-) 我是一个字典,其中每个值都是一个类实例。我访问它 使用: for k,v in self.panels.panel_list.items(): print" ;编号:\t",v.number print" Level:\t",v.level print" Location:\t", v.location print" MOPS:\t",v.mops print" List length:\t",len(v.mops) print" Matrix:\t",v.matrix," \ n \ n" 此输出将为(对于一个给定的键值): 数量:181 等级:ovride + supvis 位置:mons = 4 v8.0 3楼 MOPS:[''287'',''288'',''289'',''290''] 列表长度:28 矩阵:kng 这真的很奇怪...我的len(v.mops)应该返回4( 中的4个元素列表)。实际上它返回28.查看大量 记录的输出,似乎长度几乎总是7次太大 (28/7 = 4)。 ...但不总是。这真是令人困惑......可以任意 建议发生了什么? 我一直在尝试将列表元素输出为字符串同样 有限的成功,但事情似乎很简单,我看不出 prblem可能在哪里...... 干杯, 本 解决方案 添加 打印类型(v.mops),repr(v.mops) 调试语句可能会为您提供所需的线索。 7 7 7 7 添加 打印类型(v.mops),repr(v.mops) 调试语句可能会为您提供所需的线索。 7 7 7 7 < / F> 添加 打印类型(v.mops),repr(v.mops) 调试语句可能会为您提供所需的线索。 7 7 7 7 < / F> Hello...hopefully my last question :-) I ave a dictionary, where each value is a class instance. I access itusing: for k, v in self.panels.panel_list.items():print "Number:\t",v.numberprint "Level:\t",v.levelprint "Location:\t",v.locationprint "MOPS:\t",v.mopsprint "List length:\t",len(v.mops)print "Matrix:\t",v.matrix,"\n\n" The output from this would be (for a given key value):Number:181Level:ovride+supvisLocation: mons=4 v8.0 3rd floorMOPS:[''287'', ''288'', ''289'', ''290'']List Length:28Matrix:kng This is really odd...my len(v.mops) ought to return 4 (4 elements inthe list). In fact it returns 28. looking at outputs from lots ofrecords, it seems that the length is almost always 7 time too great(28/7=4)....but not always. This is really confusing...can anyonsuggest what is going on? I''ve been trying to output the list elements as a string with equallylimmited success, but the thing seems so simple I can''t see where theprblem might lie.... Cheers, Ben 解决方案 adding a print type(v.mops), repr(v.mops) debug statement might provide you with the clues you need. 7 7 7 7 </F> adding a print type(v.mops), repr(v.mops)debug statement might provide you with the clues you need. 7 7 7 7</F> adding a print type(v.mops), repr(v.mops) debug statement might provide you with the clues you need. 7 7 7 7 </F> 这篇关于Bizzare长度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 04:28