Solved

How to create a file using python in exos

  • 11 April 2019
  • 2 replies
  • 343 views

Hi,

I'm trying to create a local file for writing and looks like I don't have a permission to do so.
I'm using custom created account but with admin privleges.

Is there any place in EXOS filesystem with write permissions?
icon

Best answer by Kawawa 11 April 2019, 17:40

You can use the open() function. I am using an admin account called pythonuser and running a pythong script that creates a file called thisFileWasCreatedWithPython.log.

code:
    fileName = "thisFileWasCreatedWithPython"
f = open('/usr/local/cfg/' + fileName + '.log', 'a')


I have RW permissions on the file after running my script:

code:
# ls *.log
-rw-r--r-- 1 admin admin 241770 Apr 11 21:29 thisFileWasCreatedWithPython.log


What version of EXOS are you using and can if you try the using the above in your script are you running into the same read only permission problem?
View original

2 replies

Userlevel 5
You can use the open() function. I am using an admin account called pythonuser and running a pythong script that creates a file called thisFileWasCreatedWithPython.log.

code:
    fileName = "thisFileWasCreatedWithPython"
f = open('/usr/local/cfg/' + fileName + '.log', 'a')


I have RW permissions on the file after running my script:

code:
# ls *.log
-rw-r--r-- 1 admin admin 241770 Apr 11 21:29 thisFileWasCreatedWithPython.log


What version of EXOS are you using and can if you try the using the above in your script are you running into the same read only permission problem?
Dunno why but I tried to create a file in /usr/local/cfg before and couldn't. I also tried at /usr/local/tmp but that didn't work either. Finally, I did it like this at /usr/local/cfg:

with open('test.xsf','w') as f:
f.write('something to file')

Thanks 😉

Reply