所以基本上我正在尝试使用 cx_Freeze 将 python 文件转换为可执行文件。我不断收到错误
TypeError: list indices must be integers or slices, not str
当尝试构建它时,我不知道是什么原因造成的。有人可以给我一些帮助吗?错误出现在第 8 行,即带有 "include_file"
的部分。但是我不确定这条线有什么问题。非常感谢任何帮助,谢谢。
import cx_Freeze
executables = [cx_Freeze.Executable("Consumo V23.py")]
cx_Freeze.setup(
name="A bit Racey",
options={"build_exe": {"packages":["pygame"],
"include_files":["Blowfish.png"]["dojo.png"]["Rice_fresh.png"]["rottenapple.png"]["rottenfish.png"]["rottenrice.png"]
["menu screen .png"]["gameover.png"]["Apple .png"]["Fish.png"]}},
executables = executables
)
最佳答案
我想象这条线
options={"build_exe": {"packages":["pygame"],
"include_files":["Blowfish.png"]["dojo.png"]["Rice_fresh.png"]["rottenapple.png"]["rottenfish.png"]["rottenrice.png"]
["menu screen .png"]["gameover.png"]["Apple .png"]["Fish.png"]}}
应该是
options={"build_exe": {"packages":["pygame"],
"include_files":["Blowfish.png", "dojo.png", "Rice_fresh.png", "rottenapple.png", "rottenfish.png", "rottenrice.png", "menu screen.png", "gameover.png", "Apple .png", "Fish.png"]}}
两个相邻的列表不会连接(就像字符串一样),列表后面的方括号是列表索引,因此 ["foo"]["bar"]
尝试使用"bar"
作为从列表 ["foo"]
中获取项目的索引。
关于python - 尝试使用 cx_Freeze 将 .py 文件转换为 .exe 时出现 TypeError : list indices must be integers or slices, not str,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57930474/