module object has no attribute open in shelve

3.6k views Asked by At

Following is my code,

import shelve

sd = shelve.open("session.data")

When I try the same code in IDLE , I am not getting any error. But when running the script with this code, I am getting the following error,

Traceback (most recent call last):
  File "try.py", line 3, in <module>
    sd = shelve.open("session.data")
AttributeError: 'module' object has no attribute 'open'
1

There are 1 answers

16
Martijn Pieters On BEST ANSWER

You imported a different module shelve, one that masks the standard library version.

Do:

import shelve
print(shelve.__file__)

and move that file aside, rename it, or delete it.