+ 1

How to store dictonries and List in filez

Suppose i have dynamic lists and depend on user choice that how many record how many record he wants to add he can added For example He run a program and add 3 recordss added when he run again that program there should be 3 record stored in file and if he want to add more record he the previous record should be maintian in file So how can i do this ? Sorrt for bad english

1st Jun 2019, 6:53 AM
Abdul Wahab
Abdul Wahab - avatar
6 Antworten
+ 6
HonFu. you were faster than me. I got the same idea with serializing objects with pickle.
1st Jun 2019, 9:48 AM
Lothar
Lothar - avatar
+ 5
There is a possibility to store dicts to a csv file (= comma separated values). Therefore use the csv module with: import csv This module has classes DictReader and DictWriter. I never used csv this way but I am sure you can find some code snippets to see how it should be. For general use of reading and writing files see my tutorial: https://code.sololearn.com/cESZeFlM1cRR/?ref=app
1st Jun 2019, 7:48 AM
Lothar
Lothar - avatar
+ 4
The pickle module is easy to use when you don't need the data outside of Python. You can also use json; codewise it's similarly easy. You can also manually write the data to a txt file and read it from there, a few more lines of code then.
1st Jun 2019, 8:23 AM
HonFu
HonFu - avatar
+ 3
Just google pickle. It is really, really simple, you will definitely get it.
1st Jun 2019, 11:19 AM
HonFu
HonFu - avatar
+ 2
Ok thanks i will
1st Jun 2019, 11:20 AM
Abdul Wahab
Abdul Wahab - avatar
0
Thankew Lothar but actually i am begginner its hard to understand for me 😢 I am a ist semester studnt and i have book managment systmet project whi h i almost completed i have used dictionaries also for bttr result now all i just i want to add files functionality in my project i just need a little idea of this thankew for your help btw 😊😊
1st Jun 2019, 11:03 AM
Abdul Wahab
Abdul Wahab - avatar