Dan Stromberg a écrit :
(snip)
> My implementation may or may not be lacking (feel free to improve it - in
> fact, please do!),
Since you ask for it:
def makeprop(name):
_name = '_' + name
def fget(self):
return getattr(self, _name, None)
def fset(self, val):
set
Dan Stromberg a écrit :
> On Fri, 12 Oct 2007 09:42:28 +0200, Bruno Desthuilliers wrote:
>
>
So what? Otherwise you carry *always* the baggage of a public
property and a private attribute whether you need this or not. At
least for me it would be unnecessary in most cases.
>>>
>>>Tha
Stargaming a écrit :
> On Thu, 11 Oct 2007 18:58:44 +0200, Bruno Desthuilliers wrote:
> [snip]
>
> Your implementation seems particularly broken. You do not return anything
> from `name()`,
Oops, my bad ! Indeed, I forgot the 'return property(**locals())' at the
end. And a couple other things
Dan Stromberg schrieb:
> On Thu, 11 Oct 2007 18:42:16 +, Marc 'BlackJack' Rintsch wrote:
>
>
>>> The "baggage" of possibly fixing (AKA "generalizing") how your attributes
>>> are accessed is something you lug around while your deadline looms.
>> Sorry I don't get it. If I want to customize t
On 10/12/07, Dan Stromberg <[EMAIL PROTECTED]> wrote:
> On Fri, 12 Oct 2007 09:42:28 +0200, Bruno Desthuilliers wrote:
>
> >>> So what? Otherwise you carry *always* the baggage of a public
> >>> property and a private attribute whether you need this or not. At
> >>> least for me it would be unnec
On Thu, 11 Oct 2007 18:42:16 +, Marc 'BlackJack' Rintsch wrote:
>> The "baggage" of possibly fixing (AKA "generalizing") how your attributes
>> are accessed is something you lug around while your deadline looms.
>
> Sorry I don't get it. If I want to customize the access to a "normal"
> att
On Oct 12, 2:55 pm, Dan Stromberg <[EMAIL PROTECTED]> wrote:
> If you have a program that needs to perform well, you're much better off
> coding your classes the best way you know how from a Software Engineering
> perspective, and using pysco or shedskin or pypy or similar to
> improve performance
On Fri, 12 Oct 2007 09:42:28 +0200, Bruno Desthuilliers wrote:
>>> So what? Otherwise you carry *always* the baggage of a public
>>> property and a private attribute whether you need this or not. At
>>> least for me it would be unnecessary in most cases.
>>
>> That "baggage" of carrying around
On Thu, 11 Oct 2007 18:58:44 +0200, Bruno Desthuilliers wrote:
[snip]
Your implementation seems particularly broken. You do not return anything
from `name()`, hereby removing name as an attribute (or: replacing it
with its return value -- None). You should return ``property(**locals())
`` (or ``
Artur Siekielski a écrit :
> George Sakkis wrote:
>> By now you must have been convinced that default getters/setters is
>> not a very useful idea in Python but this does not mean you can't do
>> it;
>
> It's a perfect summary of my thoughts after reading this thread. I
> will use public attribute
Dan Stromberg a écrit :
> On Thu, 11 Oct 2007 13:46:12 +, Marc 'BlackJack' Rintsch wrote:
>
>> On Thu, 11 Oct 2007 13:04:53 +, Artur Siekielski wrote:
>>
>>> On Oct 11, 2:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
But why? Default getters and setters are unnecessary a
George Sakkis wrote:
> By now you must have been convinced that default getters/setters is
> not a very useful idea in Python but this does not mean you can't do
> it;
It's a perfect summary of my thoughts after reading this thread. I
will use public attributes (with access customizable with prope
On Oct 11, 7:04 pm, George Sakkis <[EMAIL PROTECTED]> wrote:
> You could take it even further by removing the need to repeat the
> attribute's name twice. Currently this can done only through
> metaclasses but in the future a class decorator would be even
> better:
Replying to myself here, but ac
On Oct 11, 7:48 am, Artur Siekielski <[EMAIL PROTECTED]>
wrote:
> I know about 'property' function in Python, but it's normal usage
> isn't declarative, because I have to code imperatively getters and
> setters:
>
> class Person(object):
>def __init__(self, name):
> self._name = name
>
On Oct 11, 7:42 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> Sorry I don't get it. If I want to customize the access to a "normal"
> attribute I simply turn it into a property.
I *think* I understand Artur's problem: he wants to be able to add
(for example) clean-up and validation co
On Oct 11, 12:48 pm, Artur Siekielski <[EMAIL PROTECTED]>
wrote:
> Hi.
>
> I would like to have declarative properties in Python, ie. something
> like slots definitions in defclass in Common Lisp. It seems that even
> Java will have it, using a library (https://bean-pr
On Thu, 11 Oct 2007 09:58:48 -0700, Dan Stromberg wrote:
> On Thu, 11 Oct 2007 13:46:12 +, Marc 'BlackJack' Rintsch wrote:
>
>> On Thu, 11 Oct 2007 13:04:53 +, Artur Siekielski wrote:
>>
>>> 1. If I use instance field 'name' which is accessed directly by other
>>> classes,
>>> and later
On Thu, 11 Oct 2007 13:46:12 +, Marc 'BlackJack' Rintsch wrote:
> On Thu, 11 Oct 2007 13:04:53 +, Artur Siekielski wrote:
>
>> On Oct 11, 2:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>>> But why? Default getters and setters are unnecessary and if you need
>>> something ot
Artur Siekielski a écrit :
> On Oct 11, 4:21 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>> In practice, it turns out to be a lot less work to deal with that
>> occasionally than to always deal with lugging around internal
>> attributes and external properties when they're really not needed.
Artur Siekielski a écrit :
> On Oct 11, 2:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> But why? Default getters and setters are unnecessary and if you need
>> something other than the default you need to write it anyway more
>> explicitly.
>
> I see some problems with your approa
Artur Siekielski a écrit :
> Hi.
>
> I would like to have declarative properties in Python, ie. something
> like slots definitions in defclass in Common Lisp. It seems that even
> Java will have it, using a library ( https://bean-properties.dev.java.net/
> ).
>
> I know a
On Thu, 11 Oct 2007 15:39:29 +, Artur Siekielski wrote:
> On Oct 11, 4:21 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>> > 2. Properties define (a part of) public interface of a class. When
>> > using fields for public access, you must tell this explicitly in
>> > documentation, or use
On Oct 11, 4:21 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> In practice, it turns out to be a lot less work to deal with that
> occasionally than to always deal with lugging around internal
> attributes and external properties when they're really not needed. By
> writing everything as pro
Artur Siekielski wrote:
> On Oct 11, 2:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> > But why? Default getters and setters are unnecessary and if you need
> > something other than the default you need to write it anyway more
> > explicitly.
>
> I see some problems with your approac
On Thu, 11 Oct 2007 13:04:53 +, Artur Siekielski wrote:
> On Oct 11, 2:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> But why? Default getters and setters are unnecessary and if you need
>> something other than the default you need to write it anyway more
>> explicitly.
>
> I
On Oct 11, 2:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> But why? Default getters and setters are unnecessary and if you need
> something other than the default you need to write it anyway more
> explicitly.
I see some problems with your approach:
1. If I use instance field 'nam
On Thu, 11 Oct 2007 11:48:18 +, Artur Siekielski wrote:
> class Person(object):
>def __init__(self, name):
> self._name = name
>def _get_name(self):
> return self._name
>def _set_name(self, new_name):
> self._name = new_name
>name = property(_get_name, _set_na
Hi.
I would like to have declarative properties in Python, ie. something
like slots definitions in defclass in Common Lisp. It seems that even
Java will have it, using a library ( https://bean-properties.dev.java.net/
).
I know about 'property' function in Python, but it's nor
28 matches
Mail list logo