import shelve
# with shelve.open("D:/WORK/2018/February/22-02-2018-Thursday/shelvetest1")as fruit:
# fruit = {"orange":"its a fruit which is orange in color",
# "apple":"good for health"}
# print(fruit)
# print(fruit["orange"])
# print("="*40)
# print(fruit["orange"])
# print(fruit)
with shelve.open("D:/WORK/2018/February/22-02-2018-Thursday/shelvetest2")as fruit:
fruit["orange"]="its a fruit which is orange in color"
fruit["apple"]="good for health"
print(fruit)
print("="*40)
#the below peice of code will throw an error
# print(fruit["orange"])
with shelve.open("D:/WORK/2018/February/22-02-2018-Thursday/shelvebike1")as bike:
bike["name"]="tvs"
bike["engine_cc"]="250 cc"
#even if removed and executes the below code it will be saved
#in the first run and remains there,which is not the case if
#it is normal dictionary
# bike["engin_cc"]="250 cc"
bike["model"]="victor"
print(bike)
for i in bike:
print(i)
print(bike[i])
###############################################################################
import shelve
with shelve.open("D:/WORK/2018/February/22-02-2018-Thursday/shelvebike1")as bike:
bike["name"]="tvs"
bike["engine_cc"]="250 cc"
#even if removed and executes the below code it will be saved
#in the first run and remains there,which is not the case if
#it is normal dictionary
# bike["engin_cc"]="250 cc"
#we can delete that key using,it has to be run one time only
# del bike["engin_cc"]
bike["model"]="victor"
print(bike)
for i in bike:
print(i)
print(bike[i])
Thursday, 22 February 2018
Python Shelve- Day 12(1 day later)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment