Re: setattr question

2009-02-19 Thread Peter Otten
TP wrote: > Hi everybody, > > I try to make a "link" (or shortcut, if you want) so that len(b_instance) > computes in fact len(a) (see the code below). I could write a method > __len__ to b, but I wonder if it is possible to make it with a > setattr/getattr trick, as I do below. > > Thanks in ad

setattr question

2009-02-19 Thread TP
Hi everybody, I try to make a "link" (or shortcut, if you want) so that len(b_instance) computes in fact len(a) (see the code below). I could write a method __len__ to b, but I wonder if it is possible to make it with a setattr/getattr trick, as I do below. Thanks in advance, Julien ###

Re: setattr question

2006-03-03 Thread Gerard Flanagan
bruno at modulix wrote: > Gerard Flanagan wrote: > > The functions were kind of related > > and meaningless outside the module they were declared - > > FWIW (and from the snippet I saw), these functions are useless even in > the module !-) > ok, ok... :-) > Unless you want to dynamically choose t

Re: setattr question

2006-03-03 Thread bruno at modulix
Gerard Flanagan wrote: > bruno at modulix wrote: > [...] > >>I don't know this HtmlElement class, nor where it comes from. >>'to_string()' (or is it toString() ?) is javaish. The pythonic idiom for >>this is implementing the __str__() method and calling str(obj) on the >>obj (which will call obj._

Re: setattr question

2006-03-03 Thread Gerard Flanagan
bruno at modulix wrote: [...] > > I don't know this HtmlElement class, nor where it comes from. > 'to_string()' (or is it toString() ?) is javaish. The pythonic idiom for > this is implementing the __str__() method and calling str(obj) on the > obj (which will call obj.__str__()). Hence my (bad) gu

Re: setattr question

2006-03-03 Thread bruno at modulix
Gerard Flanagan wrote: > bruno at modulix wrote: > (snip french) > > I was trying to implement the factory pattern. > The recipe above uses 'apply' which is deprecated according to the > docs, and I suppose I was curious how to do the same sort of thing > without 'apply'. def fun(*args, **kwargs

Re: setattr question

2006-03-03 Thread bruno at modulix
bruno at modulix wrote: (snip) > Je ne vois pas très bien à quoi sert cette classe (à moins bien sûr > qu'il y ait d'autre code). Pour ce que je vois là, pourquoi ne pas > appeler directement les classes HtmlPage, HtmlElement et HtmlLiteral ? > oops, sorry, forgot to remove this before posting :(

Re: setattr question

2006-03-02 Thread Kent Johnson
Gerard Flanagan wrote: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/86900 > > mais il utilise 'apply', qui est...blah > > I was trying to implement the factory pattern. > The recipe above uses 'apply' which is deprecated according to the > docs, and I suppose I was curious how to

Re: setattr question

2006-03-02 Thread Gerard Flanagan
Fredrik Lundh wrote: > Gerard Flanagan wrote: > > > I have the following code: > > > > builder.py # > > class HtmlBuilder(object): > > > > @staticmethod > > def page(title=''): > > return HtmlPage(title) > > > > @staticmethod > > def element(tag, text=None, **at

Re: setattr question

2006-03-02 Thread Gerard Flanagan
bruno at modulix wrote: > Gerard Flanagan wrote: > > Hello > > > > I have the following code: > > > > builder.py # > > class HtmlBuilder(object): > > > > @staticmethod > > def page(title=''): > > return HtmlPage(title) > > > > @staticmethod > > def element(tag,

Re: setattr question

2006-03-02 Thread Fredrik Lundh
Gerard Flanagan wrote: > I have the following code: > > builder.py # > class HtmlBuilder(object): > > @staticmethod > def page(title=''): > return HtmlPage(title) > > @staticmethod > def element(tag, text=None, **attribs): > return HtmlElement(tag, text

Re: setattr question

2006-03-02 Thread bruno at modulix
Gerard Flanagan wrote: > Hello > > I have the following code: > > builder.py # > class HtmlBuilder(object): > > @staticmethod > def page(title=''): > return HtmlPage(title) > > @staticmethod > def element(tag, text=None, **attribs): > return HtmlElem

setattr question

2006-03-02 Thread Gerard Flanagan
Hello I have the following code: builder.py # class HtmlBuilder(object): @staticmethod def page(title=''): return HtmlPage(title) @staticmethod def element(tag, text=None, **attribs): return HtmlElement(tag, text, **attribs) @staticmethod de