Sparky
Jul 04, 2015 - 10:04
I am trying figure out how to persist my data using pythonista on my ipad. All i can find in the documentation seems to be general python ruuning on a computer.
I am trying figure out how to persist my data using pythonista on my ipad. All i can find in the documentation seems to be general python ruuning on a computer.
My recommendation is that you treat Pythonista as if it was a general Python running on a computer. For most basic stuff you will see that Pythonista is a full-featured Python implementation.
Your first approach to persistance should be writing to and reading from a local file:
valuable_data = "Tomorrow's winning lottery number is: 07 09 11 17 21 24 37"
# write data to a local file
with open('valuable_data.txt', 'w') as out_file:
out_file.write(valuable_data)
# then later on you can...
# read data from a local file
with open('valuable_data.txt', 'r') as in_file:
new_copy = in_file.read()
print(new_copy)
Additionally, the following libraries (and others) are all built into Pythonista to enable various flavors of persistence:
# roughly in the order in which I would use them myself
import json, shelve, pickle, sqlalchemy, sqlite3, zipfile, tarfile, bz2
don't forget keychain, which can be used for storing small bits of text, like passwords.
This thread also has some useful answers to a similar question.