Skip to main content
4 votes
3 answers
199 views

I'm experimenting with asynchronous patterns in Python and was curious what happens if I define a __del__ method using async def in Python 3.12. For example: class MyClass: async def __del__(self):...
LucasL's user avatar
  • 1
3 votes
3 answers
728 views

I want to cache instances of a class because the constructor is complicated and repeated uses won't alter the contents. This works great. However, I want to create a classmethod to clear the cache. In ...
steveo225's user avatar
  • 12k
2 votes
1 answer
587 views

somewhat inexperienced in python. I am coming from C# world, and I am trying to figure out what is the best practice to create a data structure in python that: can have empty fields (None) can have ...
concentriq's user avatar
-1 votes
1 answer
251 views

python newbie: I need to create an empty data model class, populate it with values and then convert it to JSON string, however i am missing something important here. see error below my data class: ...
isswf's user avatar
  • 191
0 votes
2 answers
113 views

I want to a method that runs when object reference count is changed. is there a method like the following code ? class Foo(): def __method__(self): print("ojbect reference count is ...
TheOnlyWayUp's user avatar
0 votes
0 answers
122 views

I'm trying to make a subclass with a @classmethod that would take as arguments an instance of its superclass and kwargs for its other fields. The goal is to be able to take an object of the general ...
Patrik Drozdík's user avatar
0 votes
0 answers
106 views

I'm working with gitlab webhooks and I need to choose which data model to use in my project. I'm using the Python-gitlab library to work with gitlab, and this library has its own data models for all ...
Industry666's user avatar
6 votes
2 answers
615 views

I stumbled upon this code that I found weird as it seems to violate the fact that python builtins call dunder methods directly from the class of the object. Using __call__ as an example, if we define ...
Zhang Daniel's user avatar
0 votes
3 answers
106 views

I'm writing code for a Deep Q Network in python. My computer has 32GB of memory but I run into significant issues as the training goes on because the replay buffer maxes out the RAM. I'm looking ...
Bryan Carty's user avatar
1 vote
1 answer
61 views

Here is what you would expect if you try and use the add operand over a type and int or between two type objects. >>> class Foo: ... pass ... >>> class Bar: ... pass ... >&...
ekiim's user avatar
  • 850
0 votes
1 answer
491 views

I have read answers for this question: What are metaclasses in Python? and this question: In Python, when should I use a meta class? and skimmed through documentation: Data model. It is very possible ...
alex_why's user avatar
  • 137
3 votes
2 answers
2k views

Imagine I have a base and a derived class like so: class A: def foo(self): pass class B(A): def foo(self): pass I wish to wrap calls foo calls made by instances of B. ...
xrisk's user avatar
  • 3,908
2 votes
1 answer
520 views

As far as I know, __weakref__ is a descriptor defined in class, so that if it invoked from the instances of the class, it will give the weakref object: from weakref import ref class A: pass obj =...
S.B's user avatar
  • 17.1k
11 votes
1 answer
3k views

According to the object.__eq__() documentation, the default (that is, in the object class) implementation for == is as follows: True if x is y else NotImplemented Still following the documentation ...
Manuel Selva's user avatar
  • 19.2k
0 votes
1 answer
561 views

I've got some imported packages with tricky structure and need to call some method that bases on lots of other methods with non-default parameters, which are not class attributes themself like ...
MosQuan's user avatar
  • 172

15 30 50 per page
1
2 3 4 5
7