将列表转换为元组时出错 [英] error converting list to tuple
问题描述
您好,
我正在尝试将元组转换为列表,
并获得''TypeError:列表对象不可删除''。
有人可以告诉我可能的原因
吗?在这个转换过程中,哈希在哪里发挥作用?
可能是我的运行时损坏了吗?
代码是在C ++扩展中执行
模块我正在开发...
感谢您的帮助,
Stefan
PS:我正在使用python 2.3.3,以防重要事项
hi there,
I''m trying to convert a tuple to a list,
and get a ''TypeError: list objects are unhashable''.
Can anybody enlighten me as to the possible causes
for this ? Where does hashing come into play during
this conversion ?
Could it be that my runtime is corrupted ?
The code is executed from within a C++ extension
module I''m developing...
Thanks for any help,
Stefan
PS: I''m using python 2.3.3 in case that matters
推荐答案
Stefan Seefeld写道:
Stefan Seefeld wrote:
你好,
我正在尝试将一个元组转换为一个列表,
并得到一个''TypeError:list objects is unhashable'' 。
任何人都可以告诉我这可能的原因吗?在这次转换过程中,哈希在哪里发挥作用?
可能是我的运行时损坏了吗?
代码是在C ++扩展中执行的模块我正在开发......
感谢您的帮助,
Stefan
PS:我正在使用python 2.3.3以防重要事项/>
hi there,
I''m trying to convert a tuple to a list,
and get a ''TypeError: list objects are unhashable''.
Can anybody enlighten me as to the possible causes
for this ? Where does hashing come into play during
this conversion ?
Could it be that my runtime is corrupted ?
The code is executed from within a C++ extension
module I''m developing...
Thanks for any help,
Stefan
PS: I''m using python 2.3.3 in case that matters
上帝我不敢相信我想我可以回答这个问题:
mylist = []
t = (''123'',''你好'',''再见'')
范围内的计数(0,len(t)):
mylist。追加(t [count])
它对我有用。
John
God I can''t believe I think I can answer this question:
mylist=[]
t=(''123'',''hello'',''bye'')
for count in range(0,len(t)):
mylist.append(t[count])
It works for me.
John
john fabiani写道:
john fabiani wrote:
Stefan Seefeld写道:
Stefan Seefeld wrote:
你好,
我正在尝试转换一个元组到列表,
并获得''TypeError:列表对象是不可用的''。
任何人都可以告诉我可能的原因
s?在这次转换过程中,哈希在哪里发挥作用?
可能是我的运行时损坏了吗?
代码是在C ++扩展中执行的模块我正在开发......
感谢您的帮助,
Stefan
PS:我正在使用python 2.3.3以防重要事项/>
hi there,
I''m trying to convert a tuple to a list,
and get a ''TypeError: list objects are unhashable''.
Can anybody enlighten me as to the possible causes
for this ? Where does hashing come into play during
this conversion ?
Could it be that my runtime is corrupted ?
The code is executed from within a C++ extension
module I''m developing...
Thanks for any help,
Stefan
PS: I''m using python 2.3.3 in case that matters
上帝我不敢相信我认为我可以回答这个问题:
mylist = []
t =(''123'',''你好' ',''再见'')
计数范围(0,len(t)):
mylist.append(t [count])
它对我有用。
John
God I can''t believe I think I can answer this question:
mylist=[]
t=(''123'',''hello'',''bye'')
for count in range(0,len(t)):
mylist.append(t[count])
It works for me.
John
甚至比上面更好:
mylist = list(t)
见我正在学习的每个人,但老人学习新的
技巧并不容易。
John
even better than above:
mylist=list(t)
See everyone I''m learning but it is not easy for an old man to learn new
tricks.
John
< br>
john fabiani写道:
john fabiani wrote:
Stefan Seefeld写道:
Stefan Seefeld wrote:
你好,
我正在尝试至 将一个元组转换为一个列表,
并得到一个''TypeError:列表对象是不可用的''。
任何人都可以告诉我这可能的原因吗?在这次转换过程中,哈希在哪里发挥作用?
可能是我的运行时损坏了吗?
代码是在C ++扩展中执行的模块我正在开发......
感谢您的帮助,
Stefan
PS:我正在使用python 2.3.3以防重要事项/>
hi there,
I''m trying to convert a tuple to a list,
and get a ''TypeError: list objects are unhashable''.
Can anybody enlighten me as to the possible causes
for this ? Where does hashing come into play during
this conversion ?
Could it be that my runtime is corrupted ?
The code is executed from within a C++ extension
module I''m developing...
Thanks for any help,
Stefan
PS: I''m using python 2.3.3 in case that matters
上帝我不敢相信我认为我可以回答这个问题:
God I can''t believe I think I can answer this question:
很好,不幸的是那不是我的问题< wink />
我这样做:
t =(''你好'',)
l = list(t)
这是标准的元组 - >列表转换。是的,
当我单独运行代码时它确实有效。
关键在于上面的内容,就像看起来一样简单,>
在非常特定的上下文中失败并带有所述异常
(我在C ++扩展模块中调用此代码),
所以我想知道是否我可能会以某种方式弄乱
python运行时,或者是否有其他
可能的异常解释。
问候,
Stefan
well, unfortunately that wasn''t my question <wink/>
I do:
t = (''hello'',)
l = list(t)
which is the standard tuple->list conversion. And yes,
it does work when I run that code in isolation.
The point is that the above, as simple as it looks,
fails with said exception in a very specific context
(I call this code from within a C++ extension module),
so I''m wondering whether I could have messed up the
python runtime somehow or whether there are other
possible explanations for the exception.
Regards,
Stefan
这篇关于将列表转换为元组时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!