omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Saving data

    Pythonista
    2
    2
    2071
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • rcrissup
      rcrissup last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

        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)
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Powered by NodeBB Forums | Contributors