[issue10609] dbm documentation example doesn't work (iteritems())
Georg Brandl ge...@python.org added the comment: Fixed in r87536. -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10609 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10609] dbm documentation example doesn't work (iteritems())
Georg Brandl ge...@python.org added the comment: Why not replace it with an example that uses get() or setdefault() then? -- nosy: +georg.brandl ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10609 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10609] dbm documentation example doesn't work (iteritems())
Éric Araujo mer...@netwok.org added the comment: IMO, wrapping db in a dict defeats the purpose of dbm implementing a mapping interface. I would use the most natural mapping idioms: - for k, v in db.iteritems(): - print(k, '\t', v) + for k in db: + print(k, '\t', db[k]) The downside of this example is that it does not explicitely call methods, making the comment about “Other dictionary methods” strange. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10609 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10609] dbm documentation example doesn't work (iteritems())
Éric Araujo mer...@netwok.org added the comment: Arg, the internal classes returned by dbm.*.open have keys but not necessarily items. See #9523, #6045 and #5736. The docs should be fixed independently of that, with the less non-idiomatic code that we can find. Do you want to check the dbm docs for other similar broken examples? I’ll review the patch. -- assignee: d...@python - eric.araujo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10609 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10609] dbm documentation example doesn't work (iteritems())
New submission from Sandro Tosi sandro.t...@gmail.com: Following http://mail.python.org/pipermail/docs/2010-December/002356.html a possible solution is: diff -r 3b07f7bb0289 Doc/library/dbm.rst --- a/Doc/library/dbm.rst Thu Dec 02 19:29:18 2010 +0100 +++ b/Doc/library/dbm.rst Thu Dec 02 21:51:06 2010 +0100 @@ -88,7 +88,7 @@ # Loop through contents. Other dictionary methods # such as .keys(), .values() also work. - for k, v in db.iteritems(): + for k, v in dict(db).items(): print(k, '\t', v) # Storing a non-string key or value will raise an exception (most How much ugly is this? alternatively, we can: for k in db.keys(): ... print(k, '\t', db.get(k)) What would be the best solution? (anyhow the comments above the for loop has to be changed). Regards, Sandro -- messages: 123113 nosy: sandro.tosi priority: normal severity: normal status: open title: dbm documentation example doesn't work (iteritems()) ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10609 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10609] dbm documentation example doesn't work (iteritems())
Éric Araujo mer...@netwok.org added the comment: Isn’t s/iteritems/items/ enough? -- nosy: +eric.araujo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10609 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10609] dbm documentation example doesn't work (iteritems())
Changes by Éric Araujo mer...@netwok.org: -- assignee: - d...@python components: +Documentation nosy: +d...@python stage: - needs patch versions: +Python 3.1, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10609 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10609] dbm documentation example doesn't work (iteritems())
Sandro Tosi sandro.t...@gmail.com added the comment: Hi Eric, on and up-to-date py3k I got this: for k, v in db.items(): ... print(k, '\t', v) ... Traceback (most recent call last): File stdin, line 1, in module AttributeError: '_dbm.dbm' object has no attribute 'items' 'items' in dir(db) False (I tried to use items() before proposing that code ;)). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10609 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com