On Tue, Aug 31, 2021 at 1:19 PM Mehrzad Saremi
wrote:
> Calvin, even if the language offered truly private members?
>
I'm saying I don't think they're necessary, especially not for the use case
posited here. Private members in other languages are about things internal
to the class of the object
Calvin, even if the language offered truly private members?
On Tue, 31 Aug 2021 at 17:31, Calvin Spealman wrote:
> The right way for those decorators to hold some private information, imho,
> isn't to put anything on the decorated object at all, but to use a weak-ref
> dictionary using the targe
The right way for those decorators to hold some private information, imho,
isn't to put anything on the decorated object at all, but to use a weak-ref
dictionary using the target object as a key.
On Sat, Aug 28, 2021 at 5:42 PM Mehrzad Saremi
wrote:
> Python currently uses name mangling for doub
The proposed semantics would be the same as self.__privs__[__class__,
"foo"]; yes I can say the problem is ugliness. The following is an example
where name mangling can be problematic (of course there are workarounds,
yet if double-underscores are meant to represent class-specific members,
the foll
On Mon, Aug 30, 2021 at 5:49 AM Mehrzad Saremi wrote:
>
> No, a class ("the class that I'm lexically inside") cannot be accessed from
> outside of the class. This is why I'm planning to offer it as a core
> feature because only the parser would know. There's apparently no elegant
> solution if you
No, a class ("the class that I'm lexically inside") cannot be accessed from
outside of the class. This is why I'm planning to offer it as a core
feature because only the parser would know. There's apparently no elegant
solution if you want to implement it yourself. You'll need to write
self.__privs
On Sun, Aug 29, 2021 at 7:40 AM Mehrzad Saremi wrote:
>
> Python currently uses name mangling for double-underscore attributes. Name
> mangling is not an ideal method to avoid name conflicting. There are
> various normal programming patterns that can simply cause name conflicting
> in double-under
Python currently uses name mangling for double-underscore attributes. Name
mangling is not an ideal method to avoid name conflicting. There are
various normal programming patterns that can simply cause name conflicting
in double-underscore members. A typical example is when a class is
re-decorated
Steven D'Aprano wrote:
def SomeClass(object):
_gridsize = 0.8
The leading underscore tells callers that they change the attribute at
their own risk.
An even more Pythonic approach is to write your class that makes no
assumptions about gridsize, and thus explicitly supports any reaso
On Mon, 25 Aug 2008 19:47:38 +0100, Ken Starks wrote:
> I have a class with an attribute called 'gridsize' and I want a derived
> class to force and keep it at 0.8 (representing 8mm).
>
> Is this a correct, or the most pythonic approach?
Others have already suggested using a property, but I'll s
Marc 'BlackJack' Rintsch wrote:
On Mon, 25 Aug 2008 21:44:49 +0100, Ken Starks wrote:
def __getattr__(self,attrname):
if attrname == 'gridsize':
return 0.8
def __setattr__(self,attrname,value):
if attrname == 'gridsize':
On Mon, 25 Aug 2008 21:44:49 +0100, Ken Starks wrote:
>>>
>>>
>>> def __getattr__(self,attrname):
>>> if attrname == 'gridsize':
>>> return 0.8
>>>
>>> def __setattr__(self,attrname,value):
>>> if attrname == 'gridsize':
>>>
André wrote:
On Aug 25, 3:47 pm, Ken Starks <[EMAIL PROTECTED]> wrote:
I have a class with an attribute called 'gridsize' and I want
a derived class to force and keep it at 0.8 (representing 8mm).
Is this a correct, or the most pythonic approach?
def __getattr__(self
On Aug 25, 3:47 pm, Ken Starks <[EMAIL PROTECTED]> wrote:
> I have a class with an attribute called 'gridsize' and I want
> a derived class to force and keep it at 0.8 (representing 8mm).
>
> Is this a correct, or the most pythonic approach?
>
>
>
> def __getattr__(self,at
On Aug 25, 2:09 pm, Ken Starks <[EMAIL PROTECTED]> wrote:
> Ken Starks wrote:
> > I have a class with an attribute called 'gridsize' and I want
> > a derived class to force and keep it at 0.8 (representing 8mm).
>
> > Is this a correct, or the most pythonic approach?
>
> >
>
>
Ken Starks wrote:
I have a class with an attribute called 'gridsize' and I want
a derived class to force and keep it at 0.8 (representing 8mm).
Is this a correct, or the most pythonic approach?
def __getattr__(self,attrname):
if attrname == 'gridsize':
I have a class with an attribute called 'gridsize' and I want
a derived class to force and keep it at 0.8 (representing 8mm).
Is this a correct, or the most pythonic approach?
def __getattr__(self,attrname):
if attrname == 'gridsize':
return 0.8
17 matches
Mail list logo