Python Forum

Full Version: Error of datebase
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import shelve
class Waiting:
   def __init__(self):
       self.name = 'Waiting'
       self.List = []
bd = shelve.open('Data')
bd['Waiting'] = Waiting()
bd.close()
bd = shelve.open('Data')
print(bd['Waiting'].name)
Error:
Traceback (most recent call last):  File "<input>", line 1, in <module>  File "C:\Python34\lib\shelve.py", line 114, in __getitem__    value = Unpickler(f).load() EOFError: Ran out of input
not sure, but shouldn't you open with writeback=True? The default is False.
Also it's better to use with context manager
Actually your code works for me in python2 and in python3 if I add .db extension to file name