>>> import pwb, pywikibot as py >>> ns = py.Site().NamespaceDict >>> ns.PROJECT.id 4 >>> ns.MAIN.id 0 >>> ns.TALK.id 1 >>> ns.USER.id 2 >>> ns.USER_TALK.id Traceback (most recent call last): File "<pyshell#183>", line 1, in <module> ns.USER_TALK.id File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 540, in __getattr__ return self.__getattribute__(attr) AttributeError: 'NamespacesDict' object has no attribute 'USER_TALK' >>> ns.PROJECT.id 4 >>> ns.PROJECT_TALK.id Traceback (most recent call last): File "<pyshell#185>", line 1, in <module> ns.PROJECT_TALK.id File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 540, in __getattr__ return self.__getattribute__(attr) AttributeError: 'NamespacesDict' object has no attribute 'PROJECT_TALK'
and calling as dict also fails
>>> ns['PROJECT TALK'].id 5 >>> ns['PROJECT_TALK'].id Traceback (most recent call last): File "<pyshell#187>", line 1, in <module> ns['PROJECT_TALK'].id File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 521, in __getitem__ return super(NamespacesDict, self).__getitem__(key) File "C:\Python38\lib\_collections_abc.py", line 655, in __getitem__ raise KeyError KeyError >>>
There are namespace constants in Namespace class which works with underlines as this is a valid identifier (and btw. it seems they where never used):
#MEDIA = -2 SPECIAL = -1 MAIN = 0 TALK = 1 USER = 2 USER_TALK = 3 PROJECT = 4 PROJECT_TALK = 5
I think NamespaceDict should respect the underlines. There are some deprecated Site method which suggest using uppercase generic namespace identifiers to get the custom namespace like
@deprecated('namespaces.TEMPLATE.custom_name', since='20160407') def template_namespace(self): """Return local name for the Template namespace.""" return self.namespace(10)
This usage proposal fails for all talk pages