#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    100
    Rep Power
    2

    Explain this short code for me?


    Code:
    while True:
                store = shelve.open('store', writeback = True)
                item = input('Enter an item: ').capitalize() 
                if not item or item == 'Break' or item == 'None':
                    break
                try:
                    store['item_quantity'][item] = int(input(('Enter the number of {0} available in the store: ').format(item)))
                    store['item_rate'][item] = float(input(('Enter the rate of {0}: ').format(item)))
                except ValueError:
                    print('Wrong value entered, enter a valid value.')
                    continue
                store.sync()
                store.close()
    The place where I am having trouble comprehending is the
    writeback=True in the second line
    and the store.sync() in the last second line

    What are they doing?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    10
    Rep Power
    0
    I believe the writeback = True is, anything accessed is cached in memory. If I also remember correctly, there is no need to use obj.sync() if you use obj.close() right after, as obj.sync() is automatically called by obj.close().

    I believe obj.sync() synchronizes the cached data with the stored data.

IMN logo majestic logo threadwatch logo seochat tools logo