修补文件系统路径不工作

2024-10-01 07:30:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近创建了一个程序,其中包括help等命令,使程序使用arg open(“文件路径”、“r”)读取名为help.tosext的文本文件。对于显示其他文本文件的其他命令,我也是这样处理的。然后,我尝试通过使用程序文件路径创建输入值来缩短这种混乱,如下所示:

filesyspath = input("Please specify the program location's path :") 

为了能做一些像

open(filesyspath,"/tosext", "r") 

(/tosext是我希望在程序中显示的所有文本文件的位置)

换句话说,我试图输入程序位置的地址,并将其放在需要一些.totext文件的函数的开头)

但是当我试图调用帮助文本文件时,它说我

Type <help> to get a list of available commands. Please specify the filesystem's location path :/storage/emulated/0/qpython/projects3/TemOS -->help Traceback (most recent call last): File "/storage/emulated/0/qpython/projects3/TemOS/.last_tmp.py", line 59, in <module> hlp = open(syspath,"/tosext/help.tosext", "r") TypeError: an integer is required (got type str)

我知道错误的来源(程序需要一个整数),但我不知道其他解决方案


Tags: 文件thepath命令路径程序helpstorage
1条回答
网友
1楼 · 发布于 2024-10-01 07:30:56

syspath"/tosext/help.tosext"必须连接在一起以形成路径:

hlp = open(syspath + "/tosext/help.tosext", "r")

open的第一个参数是路径(一个字符串),第二个参数是模式(另一个字符串),第三个参数是缓冲(一个整数)。通常,您不希望使用第三个参数

相关问题 更多 >