AttributeError: 'list' object has no attribute 'item' Ask

↘锁芯ラ 提交于 2019-12-11 07:07:09

问题


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

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.

Following is my code:

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

This is the error

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:


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

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}


来源:https://stackoverflow.com/questions/46087979/attributeerror-list-object-has-no-attribute-item-ask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!