AttributeError:“列表"对象没有属性“项目" [英] AttributeError: 'list' object has no attribute 'item' Ask

查看:183
本文介绍了AttributeError:“列表"对象没有属性“项目"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了意外错误.我意识到有些帖子有类似的错误,但要么无法理解答案,要么无法将其与我的案例(词典)联系起来.

I am getting an unexpected error. I realize that there are posts with similar errors but either could not understand the answer or could not relate it to my case (dictionary).

我正在尝试为输入文件的每一行计算相似性得分,并且在每次迭代时(即对于输入文件的每一行)将得分的前20个值存储在字典中.

I am trying to calculate a similarity score for each line of an input file and at every iteration (i.e for each line of input file) store the top 20 values of the score in a dictionary.

以下是我的代码:

import sys
from cx_Freeze import setup, Executable

includefiles = ['Arcade Funk.mp3', 'game over.wav', 'FrogTown.wav','pixel ufo.png','introBackground.png','pixel playButton.png','pixel instructionButton.png','pixel playButtonHighlighted.png','pixel instructionButtonHighlighted.png','instructionPage.png','crashBackground.png','space background long.png','pixel earth.png','pixel asteroid.png', 'pixel icon.png','Montserrat-ExtraBold.otf','Montserrat-Bold.otf','arial.ttf']
includes = []
excludes = ['Tkinter']
packages = ['pygame']
build_exe_options = {'includes':[includes],'packages':[packages], 'excludes':[excludes], 'include_files':[includefiles]}

base = None
if sys.platform == 'win64':
    base = 'Win64GUI'
elif sys.platform == 'win32':
    base = 'Win32GUI'

setup(  name = 'Earth Invaders',
        version = '0.1',
        author = 'Victor Olawale-Apanpa',
        description = 'Slider Game: Space',
        options = {'build_exe': [build_exe_options]},
        executables = [Executable('EarthInvaders.py', base=base)]
)

这是错误

Traceback (most recent call last):
   File "C:/Users/Vix_Ox/Desktop/Earth Invaders/setup.py", line 21, in <module>
executables = [Executable('EarthInvaders.py', base=base)]
  File "C:\Users\----\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\cx_Freeze\dist.py", line 349, in setup
distutils.core.setup(**attrs)
  File "C:\Users\----\AppData\Local\Programs\Python\Python36-32\lib\distutils\core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
  File "C:\Users\----\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\dist.py", line 24, in __init__
distutils.dist.Distribution.__init__(self, attrs)
  File "C:\Users\----\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 237, in __init__
for (opt, val) in cmd_options.items():
 AttributeError: 'list' object has no attribute 'items'

推荐答案

您似乎一直在关注文档很好.

It looks like you've been following the documentation fine.

我认为问题是第20行上有一些额外的方括号:[build_exe_options]应该为build_exe_options.该变量应该是字典,但是会得到一个列表,因此会出现错误.

I think the issue is some extra square braces on line 20: [build_exe_options] should be build_exe_options. That variable is expected to be a dictionary, but it's getting a list, thus the error.

setup(  name = 'Earth Invaders',
        version = '0.1',
        author = 'Victor Olawale-Apanpa',
        description = 'Slider Game: Space',
        options = {'build_exe': build_exe_options},
        executables = [Executable('EarthInvaders.py', base=base)]
)

您可能还会发现,必须将其追溯应用到较早的行,因为在声明它们时,它们已经封装在列表中了.

You may also find that you have to apply this retroactively to an earlier line, as they are already encapsulated in lists when they are declared:

build_exe_options = {'includes':includes,'packages':packages, 'excludes':excludes, 'include_files':includefiles}

这篇关于AttributeError:“列表"对象没有属性“项目"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆