Open erlend-aasland opened 9 months ago
Lib/dbm/__init__.py contains a tiny if __name__ == "__main__" section that repeatedly calls dbm.whichdb on each of the given arguments:
Lib/dbm/__init__.py
if __name__ == "__main__"
dbm.whichdb
https://github.com/python/cpython/blob/841eacd07646e643f87d7f063106633a25315910/Lib/dbm/__init__.py#L188-L190
Test session:
$ python3 Python 3.13.0a3+ (heads/main-dirty:841eacd076, Jan 26 2024, 00:39:26) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import dbm >>> import dbm.gnu >>> import dbm.ndbm >>> import dbm.dumb >>> dbm.gnu.open("gnu.db", "c").close() >>> dbm.ndbm.open("ndbm.db", "c").close() >>> dbm.dumb.open("dumb.db", "c").close() $ python3 -m dbm gnu.db ndbm.db dumb.db other.db python3: No module named dbm.__main__; 'dbm' is a package and cannot be directly execute $ python3 -m dbm.__init__ gnu.db ndbm.db dumb.db other.db dbm.dumb dumb.db dbm.gnu gnu.db dbm.ndbm ndbm.db UNKNOWN other.db
Some observations:
__main__.py
__init__.py
Suggesting either to:
FTR, I suggest the latter: let's improve the CLI and promote it in the dbm docs.
bug/feature; hard to say :)
Bug report
Lib/dbm/__init__.py
contains a tinyif __name__ == "__main__"
section that repeatedly callsdbm.whichdb
on each of the given arguments:https://github.com/python/cpython/blob/841eacd07646e643f87d7f063106633a25315910/Lib/dbm/__init__.py#L188-L190
Test session:
Some observations:
__main__.py
; we must execute__init__.py
in order to run the scriptSuggesting either to:
__main__.py
, add docs, add a simple argparse CLI, ...)