Hi Alan,
> One last point. While I remain interested in examples of how
> "late" addition ofattributesto class instances is useful,
> I must note that everyone who responded agreed that it
> has been a source of bugs. This seems to argue against a
> general ban on "locking" objects in some way, i
On Feb 26, 9:48 pm, "Alan Isaac" <[EMAIL PROTECTED]> wrote:
> I have a class whose instances should only receive attribute
> assignments for attributes that were created at inititialization.
> If slots are not appropriate, what is the Pythonic design for this?
Hi !
Even though a lot of people hav
>
> One last point. While I remain interested in examples of how
> "late" addition of attributes to class instances is useful,
> I must note that everyone who responded agreed that it
> has been a source of bugs. This seems to argue against a
> general ban on "locking" objects in some way, in som
Alan Isaac a écrit :
> The security application seems to call for roles.
Considering that a role is a set of permissions in a context. The
application doesn't want to say "you need this role", but "you need to
have a role that has this permission" (nb : this is based on Zope's
security model).
The security application seems to call for roles.
I'll have to think about the schema example.
But in any case, my question was poorly stated.
I started out wanting to trap was the dynamic
addition of attributes to class instances after
initialization. While you responded to my later question
as as
Alan Isaac a écrit :
> "Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote in
> message news:[EMAIL PROTECTED]
>
>>I don't share your definition of "reasonable". But you should have
>>guessed by now
>
>
> My view may be shaped by a different experience.
> I have found dynamic attribute creation conv
On 28 Feb, 15:39, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> > However I will observe that
> > - entire languages are structured on the premise that dynamic
> > attribute creation can be hazardous
>
> Yup, and you are free to use one of them. And as an additional benefit, they
> will be more p
"greg" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> There's a problem with that when you want to subclass:
Agreed. The following addresses that and, I think, some
of the other objections that have been raised.
Alan
class Lockable:
a = 0
def __init__(self, lock=False):
"Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote in
message news:[EMAIL PROTECTED]
> I don't share your definition of "reasonable". But you should have
> guessed by now
My view may be shaped by a different experience.
I have found dynamic attribute creation convenient
when doing something "quick a
On Feb 26, 10:48 pm, "Alan Isaac" <[EMAIL PROTECTED]> wrote:
> I have a class whose instances should only receive attribute
> assignments for attributes that were created at inititialization.
> If slots are not appropriate, what is the Pythonic design for this?
>
> Thanks,
> Alan Isaac
There is a
Alan Isaac wrote:
> class NothingNew:
> a = 0
> def __init__(self):
> self.b = 1
> self.initialized = True
There's a problem with that when you want to subclass:
class NothingElseNew(NothingNew):
def __init__(self):
NothingNew.__init__(self)
self.c
En Wed, 28 Feb 2007 09:41:47 -0300, Alan Isaac <[EMAIL PROTECTED]>
escribió:
> However I will observe that
> - entire languages are structured on the premise that dynamic
> attribute creation can be hazardous
That's why we have so many languages to choose from. What is highly
important for so
Alan Isaac a écrit :
> Ben Finney writes:
>
>>Really, though, adding attributes to an instance is a normal thing to
>>do in Python, and you've not yet shown why you want that normal
>>functionality to be special-cased here.
>
>
>
> I accept your earlier point that if an interface changes
> one
> However I will observe that
> - entire languages are structured on the premise that dynamic
> attribute creation can be hazardous
Yup, and you are free to use one of them. And as an additional benefit, they
will be more performant because you then can optimize the code further.
But they certain
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> The easy, but inelegant, way is to set a flag.
That is the approach I explored here:
http://mail.python.org/pipermail/python-list/2007-February/428562.html
Btw, I add some background comments about "why" here:
http://
Ben Finney writes:
> Really, though, adding attributes to an instance is a normal thing to
> do in Python, and you've not yet shown why you want that normal
> functionality to be special-cased here.
I accept your earlier point that if an interface changes
one can just trap use of the old interfac
On Tue, 27 Feb 2007 20:59:03 +, Alan Isaac wrote:
> "Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> class Difficult(object):
> def __setattr__(self, name, value):
> if self.__dict__.has_key(name):
> print "'%s' exists as an instance att
"Alan Isaac" <[EMAIL PROTECTED]> writes:
> OK, let me approach this from a new direction. Suppose I define a
> class that behaves I think as I stipulated::
>
> class NothingNew:
> a = 0
> def __init__(self):
> self.b = 1
> self.initialized = True
> def __setattr__(self
OK, let me approach this from a new direction.
Suppose I define a class that behaves I think
as I stipulated::
class NothingNew:
a = 0
def __init__(self):
self.b = 1
self.initialized = True
def __setattr__(self, attr, val):
if not hasattr(self,'initialized') or
On 2/27/07, Alan Isaac <[EMAIL PROTECTED]> wrote:
> "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > def __setattr__(self, attr, val):
> > if hasattr(self, attr):
> > self.__dict__[attr] = val
> > else:
> > # Tell the user off
>
> But then
"Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> def __setattr__(self, attr, val):
> if hasattr(self, attr):
> self.__dict__[attr] = val
> else:
> # Tell the user off
But then you cannot even set attributes during initialization, right?
I wan
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
class Difficult(object):
def __setattr__(self, name, value):
if self.__dict__.has_key(name):
print "'%s' exists as an instance attribute" % name
self.__dict__[name] = value
elif
"Alan Isaac" <[EMAIL PROTECTED]> writes:
> "Ben Finney" <[EMAIL PROTECTED]> wrote:
> > The Pythonic design is: don't expect to have such control over
> > users of your code.
>
> I know this is a popular response, but the fact of the matter
> remains that it can be helpful to know when someone trie
On 27 Feb, 06:40, "Alan Isaac" <[EMAIL PROTECTED]> wrote:
> So my question remains:
> how best to trap any such attempt
> subsequent to object initialization?
> (I am willing to have properties for
> all data attributes, if that helps.)
>
You can define the __setattr__ method in your class as
def
On Tue, 27 Feb 2007 06:40:29 +, Alan Isaac wrote:
> "Ben Finney" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> The Pythonic design is: don't expect to have such control over users
>> of your code.
>
> I know this is a popular response,
It's popular for good reason.
> but
"Ben Finney" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> The Pythonic design is: don't expect to have such control over users
> of your code.
I know this is a popular response,
but the fact of the matter remains that
it can be helpful to know when someone
tries to set a value for
"Alan Isaac" <[EMAIL PROTECTED]> writes:
> I have a class whose instances should only receive attribute
> assignments for attributes that were created at inititialization.
> If slots are not appropriate, what is the Pythonic design for this?
The Pythonic design is: don't expect to have such contr
Alan Isaac wrote:
> I have a class whose instances should only receive attribute
> assignments for attributes that were created at inititialization.
> If slots are not appropriate, what is the Pythonic design for this?
>
> Thanks,
> Alan Isaac
>
>
My understanding of "Pythonic design" is not to
I have a class whose instances should only receive attribute
assignments for attributes that were created at inititialization.
If slots are not appropriate, what is the Pythonic design for this?
Thanks,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
29 matches
Mail list logo