phil
phil

Reputation: 15

Patchwork Filesystem path doesn't works

I recently created a program including commands like help, that make the program read a text file named help.tosext using the arg open("file path", "r"). I proceeded like that for other commands displaying other text files. Then I tried to shorten this mess by creating a input value with the program files path, as following :

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

In order to be able to do something like

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

(/tosext is the location of all the text files that I d'like to display in my program)

In other words, I tried to make an input with the adress of the program's location, and to put it at the beginning of a function needing some .tosext files)

But when I tried to invoke the help text file, it said me

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)

I know where the errors comes from (the programs expects an integer) but I don't know other solutions to do that.

Upvotes: 1

Views: 25

Answers (1)

DYZ
DYZ

Reputation: 57105

syspath and "/tosext/help.tosext" must be joined together to form the path:

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

The first parameter of open is the path (a string), the second is the mode (another string), and the third is buffering (an integer). Normally, you do not want to use the third parameter.

Upvotes: 1

Related Questions