Python: ein Modul tiefstellen
Ich habe versucht, so etwas zu machen:
module.py
<code>def __getitem__(item): return str(item) + 'Python' </code>
test.py
<code>import module print module['Monty'] </code>
Ich habe erwartet, dass "MontyPython" gedruckt wird. Dies funktioniert jedoch nicht:
<code>TypeError: 'module' object is not subscriptable </code>
Ist es möglich, ein subskriptierbares Modul in reinem Python zu erstellen (d. H. Ohne den Quellcode zu ändern, Affen-Patches usw.)?