HP Forums
How to specify full directory path in Python - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: How to specify full directory path in Python (/thread-17310.html)



How to specify full directory path in Python - jfelten - 08-03-2021 12:56 AM

Whenever I run something like

Code:
import uio

with uio.open('/Python.hpappdir/main.py', 'r') as mainPy:
    pass

it gives me OSError: 0, which from my experience translates to "file not found"

I was wondering how I am supposed to format a directory on the Prime.


RE: How to specify full directory path in Python - Dougggg - 08-03-2021 03:22 AM

Reading from the file section of the python app I was able to use

with open("test.txt",'r',encoding = 'utf-8') as f:

and

with open("test.txt",'w',encoding = 'utf-8') as f:

wrote the file to the file section of the app

looks like the main.py is stored there to some maybe if you add "Files" to the path


RE: How to specify full directory path in Python - jfelten - 08-03-2021 11:31 AM

What if I want to open files from different apps, or if I want to access file in the root directory, like cas.hpesettings, or any of the PPL programs? How to I format the path for stuff like that?


RE: How to specify full directory path in Python - Tim Wessman - 08-03-2021 12:16 PM

I was not involved with this part, but I am quite certain that the "root" directory for the python code will be considered to be inside the app... security concerns and stability being the primary drivers I would assume. Probably cannot access without some sort of path traversal bug.


RE: How to specify full directory path in Python - jfelten - 08-22-2021 04:49 PM

Is it possible to access files from other apps using sys.path?