descriptor Questions
1
According to Python's documentation,
Data descriptors with __set__() and __get__() defined always override a redefinition in an instance dictionary.
I have no problem understanding this senten...
Inaugural asked 22/10, 2012 at 7:59
2
I'm confused as to when to use a property vs a descriptor. I read that a property is a specialized descriptor.
Can someone please post how this works?
Druid asked 11/10, 2012 at 18:21
1
This naive class attempts to mimic the attribute access of basic python objects. dict and cls explicitly stores the attributes and the class. The effect is that accessing .x of an instance will ret...
Detestation asked 3/10, 2012 at 13:8
2
Solved
Say I define this descriptor:
class MyDescriptor(object):
def __get__(self, instance, owner):
return self._value
def __set__(self, instance, value):
self._value = value
def __delete__(self...
Contact asked 10/5, 2011 at 3:20
1
Solved
I have this code;
class NumberDescriptor(object):
def __get__(self, instance, owner):
name = (hasattr(self, "name") and self.name)
if not name:
name = [attr for attr in dir(owner) if getattr(o...
Alisun asked 28/8, 2012 at 16:20
4
Solved
I'm trying to create a Python property where in-place adding is handled by a different method than retrieving the value, adding another value and reassigning. So, for a property x on an object o,
...
Furnish asked 16/8, 2012 at 13:13
2
Solved
Could you please let me know whether weblogic-application.xml can be added in a WAR file and if so, then how to do the same.
Bertiebertila asked 22/5, 2012 at 6:37
2
Solved
Or does the attribute have to be defined outside of any class methods?
So my descriptor object is this. The IDN object already has some information about the UserNameField, so I want to use it.
c...
Thracian asked 19/4, 2012 at 16:6
1
I am trying to generate some class definitions dynamically (for wrapping a C++ extension). The following descriptor works fine except when I try to access the docstring for a field using help(), it...
Bugloss asked 6/4, 2012 at 14:53
2
Solved
I'm writing a python class that uses __setattr__ and __getattr__ to provide custom attribute access.
However, some attributes can't be handled in a generic way, so I was hoping to use descriptors ...
Approbate asked 6/2, 2012 at 14:6
2
Solved
I have recently stated trying to use the newer style of classes in Python (those derived from object). As an excersise to familiarise myself with them I am trying to define a class which has a numb...
Cortese asked 11/8, 2011 at 11:18
3
Solved
I'm attempting to build a decorator for an instance method of a class that will memoize the result. (This has been done a million times before) However, I'd like the option of being able to reset t...
Baa asked 13/12, 2010 at 17:38
1
Solved
For example, its part of the Jikes RVM stack.
at [0x70cfba90, 0x708cfaa4] Lorg/apache/lucene/index/SegmentInfos;
**access$000**(Ljava/lang/String;)V
at [0x70cfbb04, 0x708b55c8] Lorg/apache/luce...
Emmeram asked 28/9, 2011 at 4:3
1
Solved
I know if you want to add a method to a class instance you can't do a simple assignment like this:
>>> def print_var(self): # method to be added
print(self.var)
>>> class MyClas...
Jarietta asked 20/9, 2011 at 19:44
4
Solved
Can I define a Python method to be both static and instance at the same time? Something like:
class C(object):
@staticmethod
def a(self, arg1):
if self:
blah
blah
So that I can call i...
Mastigophoran asked 5/5, 2011 at 4:17
4
Solved
I'd like to be able to do this:
class A(object):
@staticandinstancemethod
def B(self=None, x, y):
print self is None and "static" or "instance"
A.B(1,2)
A().B(1,2)
This seems like a problem ...
Hardison asked 28/4, 2011 at 1:17
2
Solved
I want a script to redirect stdout and stderr to a file, do a bunch of stuff, then undo those redirections and take action on the file contents. I'm trying:
function redirect(){
exec 3>&1
...
Schlueter asked 27/4, 2011 at 17:51
1
Solved
How is __slots__ implemented in Python?
Is this exposed in the C interface?
How do I get __slots__ behaviour when defining a Python class in C via PyTypeObject?
Mystical asked 20/2, 2011 at 15:10
1
Solved
I want to create a decorator that works like a property, only it calls the decorated function only once, and on subsequent calls always return the result of the first call. An example:
def SomeCla...
Durkheim asked 13/7, 2010 at 13:34
1
Solved
I have a decorated function (simplified version):
class Memoize:
def __init__(self, function):
self.function = function
self.memoized = {}
def __call__(self, *args, **kwds):
hash = args
try:...
Differentiate asked 23/3, 2010 at 16:5
5
Solved
This question is similar to this other one, with the difference that the data member in the base class is not wrapped by the descriptor protocol.
In other words, how can I access a member of the b...
Grade asked 29/6, 2009 at 10:3
© 2022 - 2024 — McMap. All rights reserved.