Python: subscript a module
问题 I was trying to do something like this: module.py def __getitem__(item): return str(item) + 'Python' test.py import module print module['Monty'] I expected "MontyPython" to be printed. However, this doesn't work: TypeError: 'module' object is not subscriptable Is it possible to create a subscriptable module in pure Python (i.e. without modifying its source code, monkey-patching, etc.)? 回答1: >>> class ModModule(object): def __init__(self, globals): self.__dict__ = globals import sys sys