[Tutor] Writing a dictionary to txt file
Joel Goldstick
joel.goldstick at gmail.com
Sun Aug 30 03:32:35 EDT 2020
On Sun, Aug 30, 2020 at 3:22 AM nzbz xx <nzbzxx at gmail.com> wrote:
>
> The original txt file is written in this format:
>
> Plant 1
> date & time
> description
> description
> description
> (Blank line)
> Plant 2
> ...
> ....
> ...
>
> I have converted this file into dict = {'Plant 1':
> ['datetime','description','description','description'], 'Plant2' :
> ['datetime',....]}. So how can i write this dict back to the txt file in
> the same format?
>
>
You may want to look at the pickle library.
https://docs.python.org/3/library/pickle.html
Writing a file that has been pickled, doesn't produce 'text', but it
allows you to save your dictionary, and later you can read the file
and unpickle it back to the dictionary you created earlier. I'm not
sure if this is what you are going for, but its how I read your
message.
More information about the Tutor
mailing list