在 Python 中使用 open() 时 OSError [Errno 22] 无效参数 [英] OSError [Errno 22] invalid argument when use open() in Python

查看:43
本文介绍了在 Python 中使用 open() 时 OSError [Errno 22] 无效参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 函数中使用它作为参数时出现问题,但是当我使用它加载图片和图标时一切正常.

I am using resource files and something is going wrong when i am using it as argument in open function, but when i am using it for loading of pictures and icons everything is fine.

推荐答案

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

That is not a valid file path. You must either use a full path

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

或者相对路径

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

这篇关于在 Python 中使用 open() 时 OSError [Errno 22] 无效参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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