Search code examples
pythonwindowsattributeerrorshelve

module object has no attribute open in shelve


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'

Solution

  • 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.