This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2014年06月05日 17:26 by Claudiu.Popa, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| shelve.patch | Claudiu.Popa, 2014年06月05日 17:26 | review | ||
| Messages (7) | |||
|---|---|---|---|
| msg219827 - (view) | Author: PCManticore (Claudiu.Popa) * (Python triager) | Date: 2014年06月05日 17:26 | |
Hello!
Working with Shelf instances in the interactive console is cumbersome because you can't have an instant feedback when running the following:
>>> from shelve import Shelf
>>> s = Shelf({})
>>> s['a'] = 1
>>> s
<shelve.Shelf object at 0x033D0AF0>
This patch adds an useful repr to Shelf objects.
>>> s
Shelf({'a': 1})
Thanks!
|
|||
| msg221340 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2014年06月23日 04:44 | |
This may not be the right repr for the usual way of creating shelves:
d = shelve.open('tmp.shl')
print(repr(d)) # I would expect the repr to show
# the underlying db instead of all the
# key/value pairs which can be passed
# in the constructors
|
|||
| msg221342 - (view) | Author: PCManticore (Claudiu.Popa) * (Python triager) | Date: 2014年06月23日 05:12 | |
The problem is that the repr of the underlying db is not very helpful either, as seen for the dbm backend.
>>> import dbm
>>> dbm.open("test", "c")
<dbm.dumb._Database object at 0x03091FC0>
>>> f=_
>>> f[b"2"] = b"a"
>>> f
<dbm.dumb._Database object at 0x03091FC0>
>>>
But it shows the content of the underlying database, not the key / value pairs passed in the constructor:
>>> shelve.open("test1")
DbfilenameShelf({})
>>> f=_
>>> f["2"] = "4"
>>> f
DbfilenameShelf({'2': '4'})
>>> f["40"] = "50"
>>> f.dict
<dbm.dumb._Database object at 0x02ACC038>
>>> f.dict.keys()
[b'40', b'2']
>>>
|
|||
| msg221450 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年06月24日 11:41 | |
I don't think this is right repr for shelve. As file's repr doesn't read and expose a content of a file, shelve's repr shouldn't read and expose all database content. |
|||
| msg221451 - (view) | Author: PCManticore (Claudiu.Popa) * (Python triager) | Date: 2014年06月24日 11:49 | |
Fair point, Serhiy. But I see the shelve more similar to a persistent, dictionary-like object, than to a file. The fact that it uses some database behind is just an implementation detail. |
|||
| msg221454 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年06月24日 12:23 | |
When shelve stores its data on a disk, it is more similar to a file. After all, it can contain gigabytes of data, much larger than Python can address in RAM. I you want more readable repr, I with Raymond, -- use the repr of the underlying db and add readable repr for dbm objects (including file name and open mode). |
|||
| msg221455 - (view) | Author: PCManticore (Claudiu.Popa) * (Python triager) | Date: 2014年06月24日 12:37 | |
Alright, I agree with you now. You can close the issue if you want. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:04 | admin | set | github: 65869 |
| 2014年06月24日 20:07:50 | berker.peksag | set | stage: patch review -> resolved |
| 2014年06月24日 20:06:31 | rhettinger | set | status: open -> closed resolution: wont fix |
| 2014年06月24日 12:37:54 | Claudiu.Popa | set | messages: + msg221455 |
| 2014年06月24日 12:23:58 | serhiy.storchaka | set | messages: + msg221454 |
| 2014年06月24日 11:49:45 | Claudiu.Popa | set | messages: + msg221451 |
| 2014年06月24日 11:41:49 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg221450 |
| 2014年06月23日 05:12:00 | Claudiu.Popa | set | messages: + msg221342 |
| 2014年06月23日 04:44:12 | rhettinger | set | messages: + msg221340 |
| 2014年06月23日 04:23:13 | rhettinger | set | assignee: rhettinger nosy: + rhettinger stage: patch review |
| 2014年06月05日 17:26:57 | Claudiu.Popa | create | |