AttributeError:'list'对象没有属性'item'Ask

时间:2017-09-07 04:43:44

标签: python dictionary error-handling attributes cx-freeze

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

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

以下是我的代码:

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'

1 个答案:

答案 0 :(得分:1)

看起来您已经关注the documentation了。

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

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)]
)

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

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