In python I am trying to write a script that will edit text files and then run executables that use those text files. It basically entails 1)opening and reading/writing to a text file, and 2)using the file I just wrote in a bash command. Here is a simple example:
import subprocess
# write file
a = ['1\n','2\n','3\n','4\n','5th and final line']
f = open('junk01.txt', 'wb')
f.writelines(a)
f.close
# show file
subprocess.call('cat junk01.txt', shell=True)
For some reason on that subprocess.call
command it is not showing the contents of the junk01.txt file. However after I run this code and type cat junk01.txt
in bash the file has been written properly. Similarly, I'm finding that after I open, write to, and close a text file and then try to use it in an executable, the file hasn't been written to yet. Any explanation on why this is and what I can do to fix it?