相关疑难解决方法(0)

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

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

AttributeError: 'dict' object has no attribute 'append'
Run Code Online (Sandbox Code Playgroud)

到目前为止,这是我的代码:

    for index, elem in enumerate(main_feeds):
        print(index,":",elem)
        temp_list = index,":",elem
    li = {}
    print_user_areas(li)

    while True:
        n = (input('\nGive number: '))


        if n == "":
          break
        else:
             if n.isdigit():
               n=int(n)
               print('\n')
               print (main_feeds[n])

               temp = main_feeds[n]
               for item in user:


                  user['areas'].append[temp]
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

python dictionary for-loop tuples

2
推荐指数
1
解决办法
2万
查看次数

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

我正在尝试附加现有的JSON文件。当我覆盖整个JSON文件时,一切都将正常运行。我无法解决的问题在附录中。在这一点上,我完全不知所措。

{
"hashlist": {
    "QmVZATT8jWo6ncQM3kwBrGXBjuKfifvrE": {
        "description": "Test Video",
        "url": ""
    },
    "QmVqpEomPZU8cpNezxZHG2oc3xQi61P2n": {
        "description": "Cat Photo",
        "url": ""
    },
    "QmYdWb4CdFqWGYnPA7V12bX7hf2zxv64AG": {
        "description": "test.co",
        "url": ""
    }
}
}%
Run Code Online (Sandbox Code Playgroud)

这是我在data ['hashlist']。append(entry)接收AttributeError的地方使用的代码:'dict'对象没有属性'append'

#!/usr/bin/python

import json
import os


data = []
if os.stat("hash.json").st_size != 0 :
    file = open('hash.json', 'r')
    data = json.load(file)
   # print(data)

choice = raw_input("What do you want to do? \n a)Add a new IPFS hash\n s)Seach stored hashes\n  >>")


if choice == 'a':
    # Add a …
Run Code Online (Sandbox Code Playgroud)

python dictionary

1
推荐指数
1
解决办法
5031
查看次数

标签 统计

dictionary ×2

python ×2

for-loop ×1

tuples ×1