I have tried a simple write .txt file in a python script using Raspberry Pi B+ but is not working. It does not show any error but I can see the file. The code is:
file = open('log.txt','r')
file.write('hi'+'\n')
file.close()
I have tried with 'w+' , 'a' , 'w'; and reboot.
python Desktop/BQ/log.py
And when opening the file it shows the error that does not exist in the directory:
cat Desktop/BQ/log.txt
Thanks for any help.
"If you're launching the program as python Desktop/BQ/log.py and it writes to log.txt, the file won't be at Desktop/BQ/log.txt, it will be at log.txt (presumably ~/log.txt if Desktop is inside your home directory)".
Thanks, the file is created where the python file is called on the terminal. In my case, it wasn't my file's directory. The file was created somewhere else. It was a such an easy thing but I couldn't figure it out.
Thanks to @Daniel Pryden and @Jonh Gordon