Forum Archive

Saving data

rcrissup

Is it possible to save data somewhere on phone like settings for an application to read when started? It would needs to persist even if the device was powered off - that is to say it can't reside in memory.

ccc
import json

file_name = 'settings_dict.json'

settings_dict = { 'user_name'    : 'rcrissup',
                  'profile_url'  : 'http://omz-forums.appspot.com/user/rcrissup',
                  'member_since' : 'Jan. 25, 2014, 7:38 p.m' }

print(settings_dict)

with open(file_name, 'w') as out_file:
    json.dump(settings_dict, out_file)   # your data has now been written to a file in the iOS file system

# open up 'settings_dict.json' in Pythonist to see your data
# turn off, reboot, etc. your iOS device
# several minutes, hours, days, months later, you can run:

with open(file_name) as in_file:
    new_dict = json.load(in_file)  # your data has been read in from file into a new dict

print(new_dict)