0

I know I can customize class attribute access by defining __getattr__ and __getattribute__, but can I do it for a certain module?

For example, foo is an imported module and x is any name not defined in foo. Can I make foo.x return 'Hello' instead of Python throwing AttributeError, no matter what x not defined in foo is referenced?

Edit 03/12/2020

This feature was added to Python 3.7

fumito
  • 324
  • 2
  • 13
  • 1
    This might be useful: http://stackoverflow.com/questions/44834/can-someone-explain-all-in-python – Alvaro Oct 14 '15 at 03:33
  • Probably a bad idea unless you have a very good reason to do this but see [this answer](http://stackoverflow.com/a/2447383/1222578) – Marius Oct 14 '15 at 03:43

0 Answers0