Linked Questions

12 votes
0 answers
8k views

I read two articles about Metaclassing in python: What is a metaclass in Python? http://jakevdp.github.io/blog/2012/12/01/a-primer-on-python-metaclasses/ And I read about the ABC(abstract base ...
arthas_dk's user avatar
  • 443
-1 votes
1 answer
513 views

Example of setting metaclass to LoggingType i spotted at my workplace. import logging as _logging class SomeClass(object): __metaclass__ = _logging.LoggingType Here is the example I have seen for ...
Ciasto piekarz's user avatar
0 votes
1 answer
301 views

I was tinkering with an example of the strategy pattern that can be found below. from __future__ import annotations from abc import ABC, abstractmethod from typing import List class Context(): ...
patrikm96's user avatar
  • 108
70 votes
2 answers
81k views

My class implements an iterator so I can do: for i in class(): But I want to be able to access the class by index as well: class()[1] How can I do that?
xster's user avatar
  • 6,727
10 votes
3 answers
24k views

Abstract base classes can still be handy in Python. In writing an abstract base class where I want every subclass to have, say, a spam() method, I want to write something like this: class Abstract(...
gotgenes's user avatar
  • 40.3k
22 votes
1 answer
6k views

I'm trying to understand the benefits of using abstract base classes. Consider these two pieces of code: Abstract base class: from abc import ABCMeta, abstractmethod, abstractproperty class CanFly:...
Derek Chiang's user avatar
  • 3,440
5 votes
4 answers
1k views

I want to extend functionality of class "list" and add custom handlers for events: "Add new item to list" and "Remove item from list". For this task I don't want to use ...
eterey's user avatar
  • 430
5 votes
1 answer
4k views

I was trying out the below python code: from abc import ABCMeta, abstractmethod class Bar: __metaclass__ = ABCMeta @abstractmethod def foo(self): pass class Bar2(Bar): def ...
codingsplash's user avatar
  • 5,085
3 votes
2 answers
3k views

I have a class which essentially functions like the example below. The constructor takes two arguments, which are both defaulted to None if no value is given. The goal of the class is that, given a ...
Thomas M's user avatar
  • 131
1 vote
4 answers
694 views

Below is a simplified version of the code I have: class Base: def __new__(klass, *args): N = len(args) try: return [Sub0, Sub1, Sub2][N](*args) except ...
Rick's user avatar
  • 45.6k
1 vote
2 answers
1k views

My first program is getting much bigger than excepted. :) import configparser config = configparser.ConfigParser() configfile = 'RealGui.ini' class FolderLeftSettings: def __init__(...
Leonick's user avatar
  • 75
3 votes
1 answer
782 views

I have two data structures, Frontier (a queue) and Explored (a set). I want to implement a custom __contains__ method that they share: class Custom_Structure: def __contains__(self, item): ...
andydavies's user avatar
  • 3,383
0 votes
1 answer
357 views

I was reading the book Fluent Python by Luciano Ramalho and I encountered the following line: Note that the built-in concrete sequence types do not actually subclass the Sequence and MutableSequence ...
Shiladitya Bose's user avatar
2 votes
1 answer
735 views

EDIT: could it be that this is just an oversight that has not been addressed? The standard types documentation includes .copy() and .clear() in the table of methods for mutable sequence types. I ...
Rick's user avatar
  • 45.6k
0 votes
2 answers
448 views

Note: although my particular use is Flask related, I think the question is more general. I am building a Flask web application meant to be customized by the user. For example, the user is expected ...
thegreatemu's user avatar

15 30 50 per page