Re: An empty object with dynamic attributes (expando)

2010-06-10 Thread dmtr
On Jun 9, 7:31 pm, a...@pythoncraft.com (Aahz) wrote: > dmtr   wrote: > > m = lambda:expando > m.myattr = 1 > print m.myattr > >1 > > That's a *great* technique if your goal is to confuse people. > -- Yeah. But it is kinda cute. Let's hope it won't get adapted (adopted ;). -- Dmitr

Re: An empty object with dynamic attributes (expando)

2010-06-09 Thread Aahz
In article <86beb1fe-36ec-4a89-b926-3bb227c09...@g39g2000pri.googlegroups.com>, dmtr wrote: > m = lambda:expando m.myattr = 1 print m.myattr >1 That's a *great* technique if your goal is to confuse people. -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraf

Re: An empty object with dynamic attributes (expando)

2010-06-05 Thread dmtr
Right. >>> m = lambda:expando >>> m.myattr = 1 >>> print m.myattr 1 -- Cheers, Dmitry -- http://mail.python.org/mailman/listinfo/python-list

Re: An empty object with dynamic attributes (expando)

2010-06-04 Thread Terry Reedy
On 6/4/2010 10:25 PM, Alf P. Steinbach wrote: As far as I can think of now, one cannot add attributes to *any* builtin-class instance, but can add attributes to any user class which does not have them disabled. >>> [].a = 3 Traceback (most recent call last): File "", line 1, in [].a = 3 Attrib

Re: An empty object with dynamic attributes (expando)

2010-06-04 Thread Alf P. Steinbach
* Terry Reedy, on 05.06.2010 03:01: On 6/4/2010 8:01 PM, dmtr wrote: Why does it have to be a one-liner? Is the Enter key on your keyboard broken? Nah. I was simply looking for something natural and intuitive, like: m = object(); m.a = 1; Usually python is pretty good providing these natural a

Re: An empty object with dynamic attributes (expando)

2010-06-04 Thread Terry Reedy
On 6/4/2010 8:01 PM, dmtr wrote: Why does it have to be a one-liner? Is the Enter key on your keyboard broken? Nah. I was simply looking for something natural and intuitive, like: m = object(); m.a = 1; Usually python is pretty good providing these natural and intuitive solutions. As far as I

Re: An empty object with dynamic attributes (expando)

2010-06-04 Thread dmtr
> Why does it have to be a one-liner? Is the Enter key on your keyboard > broken? Nah. I was simply looking for something natural and intuitive, like: m = object(); m.a = 1; Usually python is pretty good providing these natural and intuitive solutions. > You have a perfectly good solution: defin

Re: An empty object with dynamic attributes (expando)

2010-06-03 Thread Steven D'Aprano
On Thu, 03 Jun 2010 14:00:11 -0700, dmtr wrote: > How can I create an empty object with dynamic attributes? It should be > something like: > m = object() m.myattr = 1 > > But this doesn't work. And I have to resort to: > class expando(object): pass m = expando() m.myatt

Re: An empty object with dynamic attributes (expando)

2010-06-03 Thread Alf P. Steinbach
* dmtr, on 03.06.2010 23:00: How can I create an empty object with dynamic attributes? It should be something like: m = object() m.myattr = 1 But this doesn't work. And I have to resort to: class expando(object): pass m = expando() m.myattr = 1 Is there a one-liner that would do the thing

An empty object with dynamic attributes (expando)

2010-06-03 Thread dmtr
How can I create an empty object with dynamic attributes? It should be something like: >>> m = object() >>> m.myattr = 1 But this doesn't work. And I have to resort to: >>> class expando(object): pass >>> m = expando() >>> m.myattr = 1 Is there a one-liner that would do the thing? -- Cheers, D