getattr for modules not classes

D

Daniel Nogradi

Is there something analogous to __getattr__ for modules?

I know how to create a class that has attributes from a list and
nothing else by overloading __getattr__ and making sure that the
accessed attribute appears in my list. Now I would like to do the same
with a module, say x.py, in which I have a list, say mylist, and after
importing x from another module I would like to be able to say x.one(
) or x.two( ) if 'one' and 'two' are in mylist and raise an exception
if they aren't. Is this possible?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,298
Messages
2,571,539
Members
48,274
Latest member
HowardKipp

Latest Threads

Top