[Tutor] Problem with data storage

Jacob S. keridee at jayco.net
Fri Dec 3 03:26:15 CET 2004


Hello,

The way I do it is as follows.

def open():
    a = open('myfile.txt','r')
    di = a.read()
    a.close()
    di = eval(di)
    return di

def save(di):
    a = open('myfile.txt','w')
    a.write(str(di))
    a.close()

def dosomethingwithdi(di):
    '''You can put whatever you want in here
    for example...'''
    open()
    print di
    di['key'] = 'value'
    save(di)
    print 'Done'

HTH,
Jacob Schmidt


> Hello,
> 
> I'm building an app that needs to get input from the user and compare
> it to data that should be in some kind of data storage file.
> The problem is that I dont know what data storage file/module to use...
> I need it to be easy for the user to edit by himself (I don't want to
> make an UI to edit the file), organized as list of pairs (or a table)
> and multy platform (if no such thing then WIN only).
> 
> Thanks!!
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


More information about the Tutor mailing list