descriptor

Why python subprocess.Popen need close_fds parameter?

Why python subprocess.Popen need close_fds parameter? Question: Creating a subprocess seems to need to close some fd from caller, e.g., if caller opened fd 0,1,2(stdin,out,err) and fd=3(file named “a.txt”), and subprocess.Popen sets “close_fd=True”, like p=subprocess.Popen(cmd,shell=True,close_fds=True,stdout=None… Does it mean: (1) fd 0-3 are closed in subprocess? (2) if fd 0-3 are closed, how could subprocess print …

Total answers: 1

Is it possible to test if object property uses a descriptor?

Is it possible to test if object property uses a descriptor? Question: I’m not convinced this is possible, but I thought I’d ask as I’m new to Python. Given an object with a property which its value is handled by a descriptor; is it possible to know that the given descriptor type was involved? Example …

Total answers: 2

Implementing bound method using descriptor

Implementing bound method using descriptor Question: My question is related to bound method object, more specifically I am trying to imitate the same behavior that functions (which are essentially descriptors) present. Let me first put here my understanding of how class_instance.function() works class D(object): def dfunc(self): … d=D() d.dfunc() # will call D.__dict__[‘dfunc’].__get__(d,D)() # gives …

Total answers: 1

Descriptors as instance attributes in python

Descriptors as instance attributes in python Question: To the question: Why can’t descriptors be instance attributes? it has been answered that: descriptor objects needs to live in the class, not in the instance because that is the way that the __getattribute__ is implemented. A simple example. Consider a descriptor: class Prop(object): def __get__(self, obj, objtype=None): …

Total answers: 3

Using both __setattr__ and descriptors for a python class

Using both __setattr__ and descriptors for a python class Question: 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 for those. A problem arises in that for a descriptor, the descriptor’s __get__ …

Total answers: 2