How to specify full directory path in Python
08-03-2021, 12:56 AM
Post: #1
 jfelten Member Posts: 56 Joined: May 2021
How to specify full directory path in Python
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.
08-03-2021, 03:22 AM (This post was last modified: 08-03-2021 03:26 AM by Dougggg.)
Post: #2
 Dougggg Member Posts: 109 Joined: Dec 2013
RE: How to specify full directory path in Python
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
08-03-2021, 11:31 AM
Post: #3
 jfelten Member Posts: 56 Joined: May 2021
RE: How to specify full directory path in Python
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?
08-03-2021, 12:16 PM (This post was last modified: 08-03-2021 12:17 PM by Tim Wessman.)
Post: #4
 Tim Wessman Senior Member Posts: 2,284 Joined: Dec 2013
RE: How to specify full directory path in Python
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.

TW

Although I work for HP, the views and opinions I post here are my own.
08-22-2021, 04:49 PM
Post: #5
 jfelten Member Posts: 56 Joined: May 2021
RE: How to specify full directory path in Python
Is it possible to access files from other apps using sys.path?
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)