database - Python proper way to store data -
i trying store names each 5 attributes. example:
name=apple attributes=[red,sweet,soft,fruit,healthy]
each names , attributes entered user. , there can many hundreds of entries. currently, way know store values write text file this:
lines=[] lines.append('{}|{}|{}|{}|{}|{} \n'.format(apple,red,sweet,soft,fruit,healthy)) myfile=open("test","a") myfile.writelines(lines) myfile.close()
so when want retrieve value, have use split('|') command individually split each lines this:
for lines in open('test'): lines_splitted=lines.split('|') if lines_splitted[0]=='apple':
is there better method store data other did above? want attributes retrievable when want calling name of item (e.g. apple) information, self taught , know python. so, looking way in python. no 3rd party or other languages.
the general term looking serialization, lot searching on or google.
probably easiest way in python, normal cases, use widely-recognized json format, supported standard library json
module.
Comments
Post a Comment