Python列表追加到列表“ AttributeError:'tuple'对象没有属性'append'”

用户3586062

好的,所以我知道您不能将元组附加到列表中。但是,尽管我已尽力而为,但我仍然收到此错误。有人可以告诉我我做错了什么还是怎么回事?

追溯(最近一次呼叫最近):listRow.append(convertedList)中文件“ C:/Users/.py”,第31行,AttributeError:“ tuple”对象没有属性“ append”

followBy是一个来自游标的字符串,并被拆分为列表形式。下面是游标将包含的一些示例数据。

followBy =“ 0 | 1 | 2 | 40”

table = [] #contains all rows (table)
row = [] #contains row
listFollowedBy = [] #contains ids 

for (var1, var2, var3, followedBy) in cursor:
   row = var1, var2, var3
   listFollowedBy = followedBy.split("| ") #Thought split always split the data into lists
   convertedList = list(listFollowedBy) #Threw this in there just to insure it was converted to a list
   row.append(convertedList)

   table.append(row)
马利克·卜拉希米(Malik Brahimi)

元组是不可变的,意味着除非重新分配,否则它们将无法更改。但是,您可以将元组添加到列表中,因为列表是可变的,这意味着可以更改它们。您需要编辑附加的顺序。

listFollowedBy.append(row)

截至目前,您的行是一个元组。元组没有append方法,列表有。为什么将列表添加到元组而不是添加到列表中?您已经向后调用了方法。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

追加到列表中的列表会产生AttributeError:'int'对象没有属性'append'

AttributeError:'tuple'对象没有属性'write',实例分段python

AttributeError:“ tuple”对象没有属性“ encode”-MySQLdb Python

AttributeError: 'tuple' 对象在 Python 3 中没有属性 'get'

Python - AttributeError: 'tuple' 对象没有属性 'fire'

Python AttributeError:“ str”对象没有属性“ append”

Python-AttributeError:“ str”对象没有属性“ append”

Python - AttributeError: 'str' 对象没有属性 'append' - 数学游戏

追加到列表将使“ int”对象没有属性“ append”

AttributeError: 'tuple' 对象没有属性 '_committed'

AttributeError:'tuple'对象没有属性'lower'

AttributeError: 'tuple' 对象没有属性 'translate'

AttributeError: 'tuple' 对象没有属性 'readlines'

AttributeError:“ tuple”对象没有属性“ strip”

AttributeError: 'tuple' 对象没有属性 'profilePic'

AttributeError: 'tuple' 对象没有属性 'product'

AttributeError:'tuple'对象没有属性'split'

'tuple'对象没有属性'append'

python将字典添加到现有字典-AttributeError:'dict'对象没有属性'append'

AttributeError: 'float' 对象没有属性 'append'

AttributeError: 'int' 对象没有属性 'append'...从两个列表中获取 dict

AttributeError: 'int' 对象没有属性 'append' 我的列表的简单问题

AttributeError:“列表”对象没有属性“对象”

python AttributeError: 'tuple' 对象没有使用 matplotlib 的属性 'show'

Python AttributeError:“ tuple”对象在hashlib.encode中没有属性“ encode”

Python namedtuple:AttributeError:'tuple'对象没有属性'end_pos'

Python Pandas to_datetime AttributeError: 'tuple' 对象没有属性 'lower'

Python-AttributeError:“ numpy.ndarray”对象没有属性“ append”

Python-AttributeError:“ _ io.TextIOWrapper”对象没有属性“ append”