<tfoot id='CcxIh'></tfoot>
    1. <small id='CcxIh'></small><noframes id='CcxIh'>

        <legend id='CcxIh'><style id='CcxIh'><dir id='CcxIh'><q id='CcxIh'></q></dir></style></legend>

          <bdo id='CcxIh'></bdo><ul id='CcxIh'></ul>
        <i id='CcxIh'><tr id='CcxIh'><dt id='CcxIh'><q id='CcxIh'><span id='CcxIh'><b id='CcxIh'><form id='CcxIh'><ins id='CcxIh'></ins><ul id='CcxIh'></ul><sub id='CcxIh'></sub></form><legend id='CcxIh'></legend><bdo id='CcxIh'><pre id='CcxIh'><center id='CcxIh'></center></pre></bdo></b><th id='CcxIh'></th></span></q></dt></tr></i><div id='CcxIh'><tfoot id='CcxIh'></tfoot><dl id='CcxIh'><fieldset id='CcxIh'></fieldset></dl></div>

        Python AttributeError:“dict"对象没有属性“append"

        时间:2023-08-31
            <tbody id='tZxxe'></tbody>
                <i id='tZxxe'><tr id='tZxxe'><dt id='tZxxe'><q id='tZxxe'><span id='tZxxe'><b id='tZxxe'><form id='tZxxe'><ins id='tZxxe'></ins><ul id='tZxxe'></ul><sub id='tZxxe'></sub></form><legend id='tZxxe'></legend><bdo id='tZxxe'><pre id='tZxxe'><center id='tZxxe'></center></pre></bdo></b><th id='tZxxe'></th></span></q></dt></tr></i><div id='tZxxe'><tfoot id='tZxxe'></tfoot><dl id='tZxxe'><fieldset id='tZxxe'></fieldset></dl></div>

                  <bdo id='tZxxe'></bdo><ul id='tZxxe'></ul>
                  <tfoot id='tZxxe'></tfoot>
                • <legend id='tZxxe'><style id='tZxxe'><dir id='tZxxe'><q id='tZxxe'></q></dir></style></legend>
                • <small id='tZxxe'></small><noframes id='tZxxe'>

                  本文介绍了Python AttributeError:“dict"对象没有属性“append"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在创建一个循环,以便将用户输入中的值连续附加到字典中,但出现此错误:

                  I am creating a loop in order to append continuously values from user input to a dictionary but i am getting this error:

                  AttributeError: 'dict' object has no attribute 'append'
                  

                  这是我目前的代码:

                      for index, elem in enumerate(main_feeds):
                          print(index,":",elem)
                          temp_list = index,":",elem
                      li = {}
                      print_user_areas(li)
                  
                      while True:
                          n = (input('
                  Give number: '))
                  
                  
                          if n == "":
                            break
                          else:
                               if n.isdigit():
                                 n=int(n)
                                 print('
                  ')
                                 print (main_feeds[n])
                  
                                 temp = main_feeds[n]
                                 for item in user:
                  
                  
                                    user['areas'].append[temp]
                  

                  有什么想法吗?

                  推荐答案

                  就像错误信息提示的那样,Python 中的字典不提供追加操作.

                  Like the error message suggests, dictionaries in Python do not provide an append operation.

                  您可以改为将新值分配给字典中它们各自的键.

                  You can instead just assign new values to their respective keys in a dictionary.

                  mydict = {}
                  mydict['item'] = input_value
                  

                  如果您想在输入值时附加值,则可以使用列表.

                  If you're wanting to append values as they're entered you could instead use a list.

                  mylist = []
                  mylist.append(input_value)
                  

                  您的行 user['areas'].append[temp] 看起来像是在尝试以键 'areas' 的值访问字典,如果您而是使用您应该能够执行附加操作的列表.

                  Your line user['areas'].append[temp] looks like it is attempting to access a dictionary at the value of key 'areas', if you instead use a list you should be able to perform an append operation.

                  使用列表代替:

                  user['areas'] = []
                  

                  在此说明中,您可能需要检查使用 defaultdict(list) 来解决您的问题的可能性.看这里

                  On that note, you might want to check out the possibility of using a defaultdict(list) for your problem. See here

                  这篇关于Python AttributeError:“dict"对象没有属性“append"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将有序元组列表保存为 CSV 下一篇:为什么 splatting 在 rhs 上创建一个元组,但在 lhs 上创建一个列表?

                  相关文章

                  <i id='yPlep'><tr id='yPlep'><dt id='yPlep'><q id='yPlep'><span id='yPlep'><b id='yPlep'><form id='yPlep'><ins id='yPlep'></ins><ul id='yPlep'></ul><sub id='yPlep'></sub></form><legend id='yPlep'></legend><bdo id='yPlep'><pre id='yPlep'><center id='yPlep'></center></pre></bdo></b><th id='yPlep'></th></span></q></dt></tr></i><div id='yPlep'><tfoot id='yPlep'></tfoot><dl id='yPlep'><fieldset id='yPlep'></fieldset></dl></div>
                  <tfoot id='yPlep'></tfoot>

                  1. <legend id='yPlep'><style id='yPlep'><dir id='yPlep'><q id='yPlep'></q></dir></style></legend>
                    1. <small id='yPlep'></small><noframes id='yPlep'>

                      • <bdo id='yPlep'></bdo><ul id='yPlep'></ul>