Bizzare长度问题 [英] Bizzare lst length problem
问题描述
您好...希望我的上一个问题:-)
我是一个字典,其中每个值都是一个类实例。我访问它
使用:
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可能在哪里......
干杯,
本
Ben写道:
此输出将是(对于给定的键值):
数字:181
等级:ovride + supvis
位置:mons = 4 v8.0 3楼
MOPS:[''287'',''288'','''289'',''290 '']
列表长度:28
矩阵:kng
这真是奇怪...我的len(v。 mops)应该返回4(
列表中的4个元素)。
添加
打印类型(v.mops),repr(v.mops)
调试语句可能会为您提供所需的线索。
实际上它返回28.查看大量的输出
记录,似乎长度几乎总是7次太大
(28/7 = 4)....但并非总是如此。
>> len(" [''287'' ,")
7
< blockquote class =post_quotes>
>> len("'''288'',")
7
>> len("'''289''," ;)
7
>> len("'''290'']")
7
啊...我的列表是一个字符串。这解释了len()结果,但不是为什么
它是一个字符串在第一位。
我有一个包含许多实例的字典以下
等级值:
班级面板:
拖把= []
def __init __(自我,数字,等级,位置,拖把,矩阵):
self.number =数字
self.level =等级
self.location = location
self.mops = mops
self.matrix = matrix
abve mops是一个列表,但是当我访问它是一个字符串...
Fredrik Lundh写道:
Ben写道:
< blockquote class =post_quotes>
此输出将是(对于给定的键值):
数字:181
级别:ovride + supvis
地点:mons = 4 v8.0 3楼
MOPS:[''287'',''288'','''289'',''290 ']
列表长度:28
矩阵:kng
这真奇怪...我的len(v.mops )应该返回4(
列表中的4个元素)。
添加
打印类型(v.mops),repr(v.mops)
调试语句可能会为您提供所需的线索。
实际上它返回28.查看大量的输出
记录,似乎长度几乎总是7次太大
(28/7 = 4)....但并非总是如此。
>> len(" [''287'',")
7
>> len("' '288'',")
7
>> len(&'''''289'',")
7
>> len("'''290'']")
7
< / F>
....当我打印出字符串时,它仍然被格式化为
期望列表到be:
< type''tr''" [''01'',''02'',''03'',''04'']" ;
Ben写道:
啊...我的列表是一个字符串。这解释了len()结果,但不是为什么
它是一个字符串在第一位。
我有一个包含许多实例的字典以下
等级值:
班级面板:
拖把= []
def __init __(自我,数字,等级,位置,拖把,矩阵):
self.number =数字
self.level =等级
self.location = location
self.mops = mops
self.matrix = matrix
abve mops是一个列表,但当我访问它时它是一个字符串...
Fredrik Lundh写道:
Ben写道:
此输出为(对于给定的键值):
数量:181
级别: ovride + supvis
位置:mons = 4 v8.0 3楼
MOPS:[' 287'',''288'',''289'',''290'']
列表长度:28
矩阵:kng
>
这真的很奇怪...我的len(v.mops)应该返回4(列表中的
中有4个元素)。
添加
打印类型(v.mops),repr(v.mops)
调试语句可能会为您提供所需的线索。
实际上它返回28.查看大量的输出
记录,似乎长度几乎总是7次太大
(28/7 = 4)....但并非总是如此。
>> len(" [''287'',")
7
>> len("'''288'',")
7
>> len("'''289'',")
7
>> len(&'''290'']")
7
< / F>
Hello...hopefully my last question :-)
I ave a dictionary, where each value is a class instance. I access it
using:
for k, v in self.panels.panel_list.items():
print "Number:\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"
The output from this would be (for a given key value):
Number: 181
Level: ovride+supvis
Location: mons=4 v8.0 3rd floor
MOPS: [''287'', ''288'', ''289'', ''290'']
List Length: 28
Matrix: kng
This is really odd...my len(v.mops) ought to return 4 (4 elements in
the list). In fact it returns 28. looking at outputs from lots of
records, it seems that the length is almost always 7 time too great
(28/7=4)....but not always. This is really confusing...can anyon
suggest what is going on?
I''ve been trying to output the list elements as a string with equally
limmited success, but the thing seems so simple I can''t see where the
prblem might lie....
Cheers,
Ben
Ben wrote:
The output from this would be (for a given key value):
Number: 181
Level: ovride+supvis
Location: mons=4 v8.0 3rd floor
MOPS: [''287'', ''288'', ''289'', ''290'']
List Length: 28
Matrix: kng
This is really odd...my len(v.mops) ought to return 4 (4 elements in
the list).adding a
print type(v.mops), repr(v.mops)
debug statement might provide you with the clues you need.
In fact it returns 28. looking at outputs from lots of
records, it seems that the length is almost always 7 time too great
(28/7=4)....but not always.
>>len("[''287'',")
7
>>len(" ''288'',")
7
>>len(" ''289'',")
7
>>len(" ''290'']")
7
</F>
Ah... my list is a string. That explains the len() results, but not why
it is a string in the dirst place.
I have a dictionary containing a number of instances of the following
class as values:
class panel:
mops =[]
def __init__(self,number,level,location,mops,matrix):
self.number=number
self.level=level
self.location=location
self.mops=mops
self.matrix=matrix
abve mops is a list, yet when I access it it is a string...
Fredrik Lundh wrote:Ben wrote:
The output from this would be (for a given key value):
Number: 181
Level: ovride+supvis
Location: mons=4 v8.0 3rd floor
MOPS: [''287'', ''288'', ''289'', ''290'']
List Length: 28
Matrix: kng
This is really odd...my len(v.mops) ought to return 4 (4 elements in
the list).
adding a
print type(v.mops), repr(v.mops)
debug statement might provide you with the clues you need.
In fact it returns 28. looking at outputs from lots of
records, it seems that the length is almost always 7 time too great
(28/7=4)....but not always.
>>len("[''287'',")
7
>>len(" ''288'',")
7
>>len(" ''289'',")
7
>>len(" ''290'']")
7
</F>
....and when I print out the string, it is still formatted as one would
expect a list to be:
<type ''str''"[''01'', ''02'', ''03'', ''04'']"
Ben wrote:Ah... my list is a string. That explains the len() results, but not why
it is a string in the dirst place.
I have a dictionary containing a number of instances of the following
class as values:
class panel:
mops =[]
def __init__(self,number,level,location,mops,matrix):
self.number=number
self.level=level
self.location=location
self.mops=mops
self.matrix=matrix
abve mops is a list, yet when I access it it is a string...
Fredrik Lundh wrote:Ben wrote:
The output from this would be (for a given key value):
Number: 181
Level: ovride+supvis
Location: mons=4 v8.0 3rd floor
MOPS: [''287'', ''288'', ''289'', ''290'']
List Length: 28
Matrix: kng
>
This is really odd...my len(v.mops) ought to return 4 (4 elements in
the list).adding a
print type(v.mops), repr(v.mops)
debug statement might provide you with the clues you need.
In fact it returns 28. looking at outputs from lots of
records, it seems that the length is almost always 7 time too great
(28/7=4)....but not always.
>>len("[''287'',")7
>>len(" ''288'',")7
>>len(" ''289'',")7
>>len(" ''290'']")7
</F>
这篇关于Bizzare长度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!