0
  commands.getoutput("touch /mytxt.txt")
  x="hello"
  commands.getoutput("echo x | cat >> /mytxt.txt".format(x))

I tried to run this code in python live interpreter , it runs perfectly ,data is inserted into the file. but when i put this code in python program it shows no such file and directory. but file mytxt gets created into the / folder

2 Answers2

0

Here is your answer:

Python Print String To Text File

If you write python code and not a shell script, I guess you want to use python built-in functions to manage your files.

RaphaMex
  • 2,781
  • 1
  • 14
  • 30
0

I just has a similar issue on a server with php code. I edited the files as root, but then the web server could not write to the file.

The issue is that Apache (or your web server) does not have read/write access. like as a Group owner to the file/folder

Setting the GROUP permission, and set the folder so the web server has full read/write access too.

Phillip Williams
  • 456
  • 2
  • 10