21-08-2009 o 18:09:02 alex23 wrote:
Unfortunately, apply() has been removed as a built-in in 3.x.
You can always implement it yourself :)
def apply(function, args=(), keywords={}):
return function(*args, **keywords)
--
Jan Kaliszewski (zuo)
--
http://mail.python.org/mailman/lis
Steven D'Aprano wrote:
On Sat, 22 Aug 2009 10:51:27 +0100, Jonathan Fine wrote:
Steven D'Aprano wrote:
There's a standard idiom for that, using the property() built-in, for
Python 2.6 or better.
Here's an example including a getter, setter, deleter and doc string,
with no namespace pollution
On Sat, 22 Aug 2009 10:51:27 +0100, Jonathan Fine wrote:
> Steven D'Aprano wrote:
>
>> There's a standard idiom for that, using the property() built-in, for
>> Python 2.6 or better.
>>
>> Here's an example including a getter, setter, deleter and doc string,
>> with no namespace pollution, import
Steven D'Aprano wrote:
There's a standard idiom for that, using the property() built-in, for
Python 2.6 or better.
Here's an example including a getter, setter, deleter and doc string,
with no namespace pollution, imports, or helper functions or deprecated
built-ins:
class ColourThing(obje
On Sat, 22 Aug 2009 08:09:52 +0100, Jonathan Fine wrote:
> Jonathan Gardner wrote:
>> On Aug 21, 9:09 am, alex23 wrote:
>>> On Aug 21, 11:36 pm, Jonathan Fine wrote:
>>>
>>> class ColourThing(object):
>>> @apply
>>> def rgb():
>>> def fset(self, rgb):
>>> self.r, self
Why I've personally stopped using it: I've always had the impression
that decorators were intended to provide a convenient and obvious way
of augmenting functions. Having one that automatically executes the
function at definition just runs counter to the behaviour I expect
from a decorator. Espe
Jonathan Gardner wrote:
On Aug 21, 9:09 am, alex23 wrote:
On Aug 21, 11:36 pm, Jonathan Fine wrote:
class ColourThing(object):
@apply
def rgb():
def fset(self, rgb):
self.r, self.g, self.b = rgb
def fget(self):
return (self.r, self.g, self.b)
On Fri, 21 Aug 2009 15:17:40 -0700, Jonathan Gardner wrote:
>> Unfortunately, apply() has been removed as a built-in in 3.x. I'm not
>> sure if it has been relocated to a module somewhere, there's no mention
>> of such in the docs.
>
> apply = lambda f: f()
>
> It's one of those functions th
Jonathan Gardner wrote:
> This is brilliant. I am going to use this more often. I've all but
> given up on property() since defining "get_foo", "get_bar", etc... has
> been a pain and polluted the namespace.
Unfortunately I can't remember who I first learned it from - it was
definitely in a post
On Aug 21, 9:09 am, alex23 wrote:
> On Aug 21, 11:36 pm, Jonathan Fine wrote:
>
> class ColourThing(object):
> @apply
> def rgb():
> def fset(self, rgb):
> self.r, self.g, self.b = rgb
> def fget(self):
> return (self.r, self.g, self.b)
> re
On Aug 21, 6:36 am, Jonathan Fine wrote:
> �...@apply
> def tags():
> value = []
> # complicated code
> return value
>
Is this different from:
tags = []
# complicated code
I can see the argument that you are cleaning up a lot of intermediary
variables upon re
alex23 wrote:
Unfortunately, apply() has been removed as a built-in in 3.x. I'm not
sure if it has been relocated to a module somewhere, there's no
mention of such in the docs.
The old use of apply()
You can save yourself the tidy up by using the same name for the
function & the label:
On Aug 21, 11:36 pm, Jonathan Fine wrote:
> It might seem odd to use 'apply' as a decorator, but it can make sense.
Yes, it's an idiom I've used myself for property declarations, but one
I find myself using less often:
class ColourThing(object):
@apply
def rgb():
def fset(self, r
13 matches
Mail list logo