I have written a Pythonista script using the ui to create and update multiple files that are stored in the Pythonista directory of iCloud. I run the script using a shortcut and I run it from both my iPhone and my iPad.
The problem is that when going back and forth between the iPhone and iPad accessing and modifying the same files, sometimes the files are not synchronized.
In the Pythonista file browser, the files, and the script are in iCloud/Pythonista3/Books directory.
For one file where I get this type of error, I open the file every time the program is run using:
myfile = open ('CurrentBooks.txt').read()
cBooks = json.loads(myfile)
The file is not explicitly closed when it is only read.
When I change the file, then I do the following:
with open('CurrentBooks.txt', 'w') as outfile:
json.dump(mydict, outfile)
outfile.close()
But I have found that, sometimes, when I add an entry to this file using the iPad, when I access the file on the iPhone, the changes are not there.
What is going on? Is this an iCloud problem? Or am I doing something wrong in the code?
Also, I wonder if this type of operation can get confused if the gui portion of the app is open at the same time on both devices. Since there appears to be no way to close the gui app from Pythonista, I have to remember to touch the 'X' to close the app each time I run it. I am sure that at times I have not done this.