gpt4 book ai didi

python - OSError [Errno 22] 在 Python 中使用 open() 时参数无效

转载 作者:太空狗 更新时间:2023-10-29 18:16:44 29 4
gpt4 key购买 nike

def choose_option(self):
if self.option_picker.currentRow() == 0:
description = open(":/description_files/program_description.txt","r")
self.information_shower.setText(description.read())
elif self.option_picker.currentRow() == 1:
requirements = open(":/description_files/requirements_for_client_data.txt", "r")
self.information_shower.setText(requirements.read())
elif self.option_picker.currentRow() == 2:
menus = open(":/description_files/menus.txt", "r")
self.information_shower.setText(menus.read())

我正在使用资源文件,当我将它用作 open 函数的参数时出了点问题,但是当我将它用于加载图片和图标时一切正常。

最佳答案

这不是一个有效的文件路径。您必须使用完整路径

open(r"C:\description_files\program_description.txt","r")

或者相对路径

open("program_description.txt","r")

关于python - OSError [Errno 22] 在 Python 中使用 open() 时参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25584124/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com