Hello, Dino Viehland ). Thank you for your participation. In your example foo is required. It works: class met(type): def __getattr__(cls, t): <here is the code> def __call__(cls, *args, **kw): <here is the code>
class cl(object): __metaclass__=met <here is the code> cl(6,y=7).tt(3,yy=4) (and so on) but cl required. And must be so: tt(3,yy=4) (and so on) -------------------------------------------------- 1)Tried this: import types class cl_mod(types.ModuleType): def __getattr__(self, *args, **kw): <here is the code> sys.modules.setdefault('ppp', cl_mod('ppp')) import ppp #(or from ppp import *) tt(3,yy=4) (and so on) does not work ((. In __getattr__ does not go. 2)and so: class cl_mod(object): def __getattr__(self, *args, **kw): <here is the code> sys.modules[__name__]=cl_mod() tt(3,yy=4) (and so on) does not work ((. In __getattr__ does not go. Until all Waterloo (. But, I think that I will overcome). > Well you can subclass the module type and implement __getattr__, you just > need to then publish the module in sys.modules yourself (or provide it via > some import loader hook). > >>>> class C(type(sys)): > ... def __getattr__(self, name): > ... return 42 > ... >>>> import sys >>>> sys.modules['foo'] = C('foo') >>>> import foo >>>> foo.blah > 42 > > I haven't read the entire thread, so this might not actually be useful > information :) > > -----Original Message----- > From: Ironpython-users > [mailto:ironpython-users-bounces+dinov=microsoft....@python.org] On Behalf > Of Jeff Hardy > Sent: Monday, September 17, 2012 1:27 PM > To: sepa...@sibmail.com > Cc: ironpython-users@python.org > Subject: Re: [Ironpython-users] How to use __ getattr__ to the current > module? > > The short answer is that you can't, in any version of Python. > > The longer answers can be found at > http://stackoverflow.com/questions/2447353/getattr-on-a-module. > > - Jeff > > On Mon, Sep 17, 2012 at 10:17 AM, <sepa...@sibmail.com> wrote: >> Hello, Vernon Cole. >> Or you probably do not understand the question, or I did not properly >> posed the question. >> I know I can define a function (ttt). And if I'm interested in __ >> getattr__, so in this case it can not be determined, or its name and >> parameters are defined at run time. >> Thank you. >> >>> Dear Sir: >>> Sorry, your question does not seem to make sense. >>> Your example appears to be a simple function call with one keyword >>> argument. To use it, you simply define the optional arguments when >>> you define the function. See the documentation at: >>> http://docs.python.org/tutorial/controlflow.html#more-on-defining-fun >>> ctions >>> >>> __getattr__ is only used within classes to emulate methods which do >>> not actually exist. That does not appear to be what you are wanting. >>> -- >>> Vernon Cole >>> >>> On Mon, Sep 17, 2012 at 4:42 AM, <sepa...@sibmail.com> wrote: >>> >>>> Hello. >>>> For example in the text of the module meets the command: >>>> ttt(4, x = 7) >>>> where and how to define __ getattr__ to handle it? >>>> Thank you. >>>> >>>> _______________________________________________ >>>> Ironpython-users mailing list >>>> Ironpython-users@python.org >>>> http://mail.python.org/mailman/listinfo/ironpython-users >>>> >>> >> >> >> _______________________________________________ >> Ironpython-users mailing list >> Ironpython-users@python.org >> http://mail.python.org/mailman/listinfo/ironpython-users > _______________________________________________ > Ironpython-users mailing list > Ironpython-users@python.org > http://mail.python.org/mailman/listinfo/ironpython-users > > > > > > _______________________________________________ Ironpython-users mailing list Ironpython-users@python.org http://mail.python.org/mailman/listinfo/ironpython-users