Questions tagged [slots]

`__slots__` is a python language feature to reduce size of object instances by dropping the builtin dictionary every python instance normally features in order to support dynamic assignment of attributes and replacing it with a fixed set of attributes (the 'slots').

__slots__ is a python language feature to reduce size of object instances by dropping the builtin dictionary every python instance normally features in order to support dynamic assignment of attributes and replacing it with a fixed set of attributes (the 'slots'). See: https://docs.python.org/2/reference/datamodel.html#slots

306 questions
3
votes
0 answers

C++ Qt Template Class Signals/Slots

So I'd like to make a template class in C++ Qt. The problem is that I'm using signals/slots in this class. My class header looks like template class Container : public QObject { Q_OBJECT protected: QVector vec; public: …
Yonji
  • 31
  • 1
  • 3
3
votes
2 answers

Why can using __slots__ make attribute access faster?

This question: Usage of __slots__? answers that __slots__ can make attribute access faster. But I want to know why? What happens when we define __slots__ in a class?
aturbo
  • 31
  • 2
3
votes
0 answers

Defining same slot in base and derived python class

The docs say: If a class defines a slot also defined in a base class, the instance variable defined by the base class slot is inaccessible (except by retrieving its descriptor directly from the base class). This renders the meaning of the program…
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
3
votes
1 answer

Dynamically create nested s4 class slot names and assign values in R

I try to assign values to nested s4 classes slots in R in a dynamic way. What I have so far is the code below. I create the following nested classes ending with nested slot of type numeric. setClass('slot', slots = c(slot =…
3
votes
1 answer

Accessing Python slots based object members in C

I have a Python class based on slots to save space class my_class(object): __slots__ = ('x', 'y') def __init__(self, x, y): self.x = x self.y = y I need to access objects of this class from a C function. When I print…
user2050283
  • 562
  • 1
  • 4
  • 9
3
votes
0 answers

Referring to a data slot (Error in object of a basic class ("NULL") with no slots)

I am running a simulation and need to refer to a matrix of parameters from a large object. Here is a snippet of the object structure itself: Formal class 'mi' [package "mi"] with 3 slots ..@ call : language .local(y = y, n.chains = ..2,…
user1638567
  • 69
  • 2
  • 5
3
votes
1 answer

mpirun: token slots not supported

I try to run a programme with: ~/mpich3/bin/mpirun --hostfile hosts_8_12.txt python simulation.py but I get this error: [mpiexec@pomegranate] HYDU_process_mfile_token (utils/args/args.c:296): token slots not supported at this…
banermatt
  • 33
  • 1
  • 3
3
votes
1 answer

How do I access an unknown instance's slot using a string?

Problem Given an instance, inst and a string attr containing the name of a slot, how can I obtain the value of the slot attr on inst? Of course, if attr were a symbol rather than a string, I would typically just use (slot-value inst attr), but it…
Felipe
  • 3,003
  • 2
  • 26
  • 44
3
votes
1 answer

Do attribute names consume memory on instance basis in python

Considering I have millions of objects with 3 __slots__ Is it more memory efficient to have short slot names like x vs. long like would_you_like_fries_with_that_cheeseburger? Or are the names allocated only once per class (opposed to once per…
Kimvais
  • 38,306
  • 16
  • 108
  • 142
3
votes
2 answers

Is it possible to add __slots__ in decorator of class that already defines __slots__?

Let me start off by saying that I understand how slots and metaclasses work in Python. Playing around with the two, I've run into an interesting problem. Here's a minimal example: def decorator(cls): dct = dict(cls.__dict__) dct['__slots__']…
user35147863
  • 2,525
  • 2
  • 23
  • 25
3
votes
1 answer

Python: __slots__ and its usage of descriptors

class Foo(object): __slots__ = ('a',) class Bar(Foo): @property def a(self): return super(Bar, self).a super(Bar, Bar()).a = 4 If I'm using this code, this doesn't work: >>> super(Bar, Bar()).a = 4 Traceback (most recent call…
Dave Halter
  • 15,556
  • 13
  • 76
  • 103
3
votes
1 answer

Subclassing a class with __slots__

I'm trying to subclass Scrapy's XPathSelector and patch in support for CSS3 selectors. XPathSelector is defined like this: class XPathSelector(object_ref): __slots__ = ['doc', 'xmlNode', 'expr', '__weakref__'] def __init__(self,…
Blender
  • 289,723
  • 53
  • 439
  • 496
2
votes
2 answers

Singleshot: SLOT with arguments

I have a strange problem. Here is my code: def method1(self, arg1, delay=True): """This is a method class""" def recall(arg1): self.method1(arg1, delay=False) return if delay: print "A: ", arg1,…
Developer09
  • 169
  • 2
  • 10
2
votes
0 answers

How get free/busy slots of outlook Sub calendars, Image attached for reference

I'm using Microsoft get/free busy https://learn.microsoft.com/en-us/graph/outlook-get-free-busy-schedule API to get busy slots in the calendar but it only gives me slots for the main calendar. I need to find sub-calender slots too. Anyone, please…
2
votes
1 answer

How to remove slot-scope in vue2.7

I upgraded my vue application to vue2.7 and I want to remove slot-scope from my application as it is removed in vue3. So in the examples, I see this for vue2: