Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
lost dictionary
#1
Hi Everyone,
Just new here, I'm doing an exercise about dictionary and pickle. I have this code which i use
to capture new data information

def data_entry(in_file):
    # create an empty dictionary
    lothold = {}
    
    # define key, value pair 
    lothold["Date"] = input("Date:")
    lothold["Product"] = input("Product:")
    lothold["LotID"] = input("Lot ID:")
    
    # dump the file using the pickle dump method
    pickle.dump(lothold, in_file)
My question is, I've open a file in "ab" mode (append/binary) mode. what will happen to the
create empty dictionary everytime i run this function? will it override the existing lothold
dictionary or it will create another lothold dictionary? meaning, if I call this function 3x
I will have 3 lothold dictionary...i don't want that to happen, i only want to keep one for
updating so on...

Thank you in advance :)

-jjpy
Reply
#2
(Jul-10-2019, 04:53 AM)jjpy Wrote: will it override the existing lothold
dictionary or it will create another lothold dictionary
The data will be appended to the file. If you call this function 3 times, all created dicts will be saved to this file (the file will grow up).

(Jul-10-2019, 04:53 AM)jjpy Wrote: i only want to keep one for
updating so on...

Look at the shelve module.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Lost Control over VLC jrockow 8 1,018 Jul-18-2023, 06:04 PM
Last Post: jrockow
  Lost Modules standenman 2 685 Jun-22-2023, 12:18 PM
Last Post: standenman
  Lost Module standenman 10 2,787 Oct-30-2021, 05:11 PM
Last Post: deanhystad
  XML Editing formatting lost ateestructural 2 1,860 Apr-08-2021, 04:41 AM
Last Post: ndc85430
  List structure lost when multiplying Protonn 2 2,201 Apr-23-2020, 04:16 AM
Last Post: buran
  variable gets lost Jordy 10 8,989 Oct-10-2016, 08:08 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020