Questions tagged [shelve]

Shelve can refer to either a Python object persistence or a pending change in a Visual Studio Workspace

A shelf in Python is a persistent, dictionary-like object. Documentation: shelve

Shelve can also refer to a pending change in the workspace within Visual Studio 2005

351 questions
5
votes
1 answer

How to implement a Python virtual filesystem using shelve

I have set up a Python script that simulates an OS. It has a command prompt and a virtual file system. I am using the shelve module to simulate the file system, being multi-dimensional in order to support a hierarchy of directories. However, I am…
elijaheac
  • 912
  • 2
  • 8
  • 23
5
votes
1 answer

Is "shelve" just a combination of "dbm" and "pickle"?

So everything that is done in shelve can be done separately with dbm and pickle?
NoName
  • 9,824
  • 5
  • 32
  • 52
5
votes
2 answers

Python `shelve` read-only mode is not working

Is shelve read only mode broken? The documentation says the flag parameter works as stated in dbm.open so I thought if I opened in read mode I shouldn't be able to change the shelve object. The page here also seems to suggest that modifying a…
ITA
  • 3,200
  • 3
  • 18
  • 32
5
votes
1 answer

python shelve dbm.error?

I'm trying to add a dict of dicts to a shelve file: >>> d = shelve.open('index.shelve') >>> d >>> print(list(d.keys())) [] >>> d['index'] = index Traceback (most recent call last): File "", line…
mathtick
  • 6,487
  • 13
  • 56
  • 101
5
votes
1 answer

Python shelve having items that aren't listed

I've been saving a bunch of dictionaries to file using Python's shelve module (with Python 3.4 on OSX 10.9.5). Each key is a string of an int (e.g., "84554"), and each value is a dictionary of dictionaries of a few smallish strings. No keys are…
Zeke
  • 617
  • 1
  • 6
  • 15
5
votes
1 answer

shelve raises EOFError after a few iterations of pickle/unpickle

I'm using the shelve module to save some data. The values of the keys of my shelve object are set objects. Pickling snippet: import shelve other_links = { 'Blue Estate The Game, 72':…
Berman
  • 143
  • 11
5
votes
0 answers

shelve library limitation on objects in python

I have been using shelve to store a ton of objects in this manner: dictionary with strings as the key and a list as the value: i.e. data["MITL"] = ["Radio And Television Broadcasting And Communications Equipment", "Communication Equipment"] or more…
brw59
  • 502
  • 4
  • 19
5
votes
6 answers

Really weird issue with shelve (python)

I create a file called foo_module.py containing the following code: import shelve, whichdb, os from foo_package.g import g g.shelf = shelve.open("foo_path") g.shelf.close() print whichdb.whichdb("foo_path") # =>…
Jesse Aldridge
  • 7,991
  • 9
  • 48
  • 75
5
votes
1 answer

How can I force python to use dumbdbm module to create a new database?

The shelve module is implemented on top of the anydbm module. This module acts as a façade for 4 different specific DBM implementations, and it will pick the first module available when creating a new database, in the following…
Ali_IT
  • 7,551
  • 8
  • 28
  • 44
5
votes
4 answers

Any way to use a tuple as key in a shelf? (Python)

I want to use a tuple (1,2,3) as a key using the shelve module in Python. I can do this with dictionaries: d = {} d[(1,2,3)] = 4 But if i try it with shelve: s = shelve.open('myshelf') s[(1,2,3)] = 4 I get: "TypeError: String or Integer object…
anon_y_mouse
5
votes
1 answer

seeing changes in shelve in TFS2010

I am using TFS 2010. I have to review code which is shelved by other developer before checkin. How can we do this in TFS2010 so that I can get his changes and review. Thanks!
venkysmarty
  • 11,099
  • 25
  • 101
  • 184
4
votes
2 answers

Easiest way to add a function to existing class

I'm using the python's built-in shelve module to manage some simple dictionaries. The problem I'm having is I want to use with shelve.open(filename) as f:, but when I try it claims DbfilenameShelf has no attribute __exit__. So, I'm guessing the…
Zac Smith
  • 328
  • 1
  • 10
4
votes
1 answer

How to convert a shelve object into a dictionary object in Python

I have a persistent dictionary created with DB = shelve.open('Database') This object is of type: class 'shelve.DbfilenameShelf' However, I want to know if it is possible to convert it back into a dictionary: class 'dict' PS: I know I can just…
Icaro Mota
  • 912
  • 1
  • 12
  • 20
4
votes
1 answer

How to use dill library for object serialization with shelve library

I'm using PyMemoize library to cache coroutine. I decorated the coroutine, but when Python calls it, I get: TypeError: can't pickle coroutine objects This happens because PyMemoize internally tries to pickle coroutine and store it inside Redis. For…
rominf
  • 2,719
  • 3
  • 21
  • 39
4
votes
1 answer

Why is a Python shelf file containing very little data so large on macOS?

I was just following along an example given in a book to illustrate the Python shelve module on macOS High Sierra. As shown below only two small tuples of short strings get stored in a shelf. And as you can see in the very last line, the resulting…
anothernode
  • 5,100
  • 13
  • 43
  • 62