All Questions

Tagged with
Filter by
Sorted by
Tagged with
3
votes
2answers
80 views

Alarm clock subclass of a clock

I have these two classes and they should remain separate classes, but I have a feeling that this could be implemented more efficiently and with less duplicate code. After googling around I still didn'...
0
votes
2answers
48 views

Ensuring that attributes referenced by a mixin are present in the children class

I have implemented the below _get_schema method to ensure that schema attribute is always present on the ...
32
votes
5answers
5k views

Chess game for my students

I teach programming, and I currently teach my class about inheritance, abstract classes, and mixins. I wrote this code as an example, and I want to be sure it is as good as possible before I release ...
-2
votes
2answers
71 views

Multiple inheritance of class broken up into modules [closed]

I have a class Main that uses fn(cls, ...) methods from several modules; they're used exclusively by ...
2
votes
1answer
40 views

Dynamic module import in a class hierarchy

I have two python libraries, let's call them lib and extended_lib, that provide a very similar public API. To be more specific, <...
2
votes
1answer
77 views

Read data from file: better approach using OOP

Suggestions to better understand when and how is convenient to use OPP. This question is a follow-up question on this post. I have a script that reads an input file. In time, the script may be ...
0
votes
1answer
110 views

OOP paradigm in python - Extend class functionalities

I am a novice of Python and I am trying to understand how to use OOP paradigm to improve my scripts. My scripts usually read some data from a formatted csv file and perform some numerical analysis. ...
4
votes
1answer
98 views

Using composition instead of inheritance and abstract classes

I have a tool that displays data in some format. For example, it can display a list of dogs in a CSV or JSON formats. In the code, I had a lot of places where I had to check the format and display ...
4
votes
0answers
47 views

Inherit docstrings from specified parent

I was recently working on some python where I was working with multiple inheritance and mixins and stuff like that, and I wanted to inherit docstrings for specific functions, from specific parents (...
4
votes
1answer
41 views

Time interval class that enhances constructor argument handling of its parent class

I am making a subclass of a well-established python class: pendulum.Period, which overrides both __new__ and ...
-2
votes
1answer
49 views

Is it ok to use subclasses to define just a couple of attributes? [closed]

I'm working with some code left from other developers. Here we have several projects we can work with. The project object is instantiated at the runtime. Then it used in other classes. There are no ...
4
votes
1answer
103 views

Overriding List subscription to create IndexedHeap for Classical Dijkstra's Algorithm

Much of the academic exposition of Dijkstra's Algorithm (such as Wikipedia, or this class page from Darmouth) relies on your priority queue having the ability decrease the key of an entry: the ...
5
votes
1answer
213 views

Wrapper to translate text in wxPython widgets

I am writing a wrapper for all widgets that contain text that needs to be translated for wxPython and make them handle the initial translation and the change of language on their own using gettext. I ...
5
votes
1answer
119 views

List subclasses of a class

Description Given a class, return all its subclasses (recursively). As you can see I've eliminated recursion using a stack. What I want reviewed Is there a better way to do this? How can I make ...
1
vote
1answer
2k views

Write a class for Team which should have function to prints players details

I have written it using aggregation but i feel its not the best way we can do this. Please suggest is there any other way to do this. I think we can also built this without using player class, just ...
2
votes
0answers
227 views

Python logging setup for a package

I'm running a package that downloads data from the internet. This package makes logging calls from different modules. Suppose I have a package 'demopackage'. Here is how my logging is currently set ...
2
votes
0answers
96 views

Tkinter GUI Python implementation using classes

I'm really struggling to understand application of classes and best practices in fairly advanced level GUIs, and such an example could be extremely helpful. Please note that this is my first GUI ...
4
votes
2answers
7k views

Structure of inheritance between Animal classes and methods

I'm trying to do some basic inheritance between the 3 classes and use some simple methods, and I'm looking to learn what should be the correct structure between them and what can be improved. ...
3
votes
2answers
40 views

Build object with different input, using super-class and sub-class style, Python 3

I want to model a object of air, the temperature of which can be given in 3 different ways: if the value is known (assuming the temperature is a constant) if a curve of the values with different time ...
6
votes
2answers
238 views

(Almost) arbitrary base ints with decorated methods

After reading this question about returning the "next" string in some alphabet (the digits, followed by upper and lowercase ASCII letters) using Java, I thought, well that's just counting, so why not ...
4
votes
1answer
216 views

Creating a game with rectangular shapes

I'm using Pygame to create a small game with few rectangle shapes. However, I want to learn more about classes, and I'm trying to use them. I'm very new to classes and inheritance, but I want to ...
19
votes
2answers
6k views

A Python wrap-around list

I want to gain experience creating data structures that look and feel like Python builtin types. As a first exercise, I've written a WraparoundList class meant to ...
1
vote
0answers
500 views

Sealing class attributes in Python

Over two years ago, someone asked a question on Stackoverflow about how to seal classes and attributes in Python after coming from a background in C#. The best answer to the question is that Pythonic ...
5
votes
0answers
692 views

Writing a metaclass to ensure a class is thread-safe

Python allows the creation of classes to be modified via metaclasses. They can perform all sorts of operations that might appear to be magical to languages that do not have the capability. The goal of ...
1
vote
0answers
1k views

Marking a class as final or sealing a class

Which of these metaclasses should be preferred, and is there room for improvement? Some people are not familiar with the philosophies that come with working in Python and have a desire embedded in ...
3
votes
0answers
41 views

Create, aggregate and plot signals using various methods for a given symbol using its historical data

I am hoping to get some help regarding code arrangement/organization using OOP concepts. My question is whether my usage of class/object selection/declaration and instantiation are sensible and what ...
1
vote
1answer
234 views

Implementing Abstract class

I used Pythons source code/documentation/textbook to come up with an abstract class and following subclasses. My requirements are: Domestic students don't require documentation International student ...
11
votes
1answer
2k views

Subclassing pathlib.Path

This arises from the SO Question subclassing pathlib.Path. The pathlib sources show that Path, when invoked, selects one of ...
10
votes
1answer
237 views

Implementing a Maybe for multidimensional data

The scenario is we're working with a REST endpoint that gives us nice JSON objects. We're using requests, and everything works wonderfully. But one day you notice that data you though was always being ...
13
votes
3answers
4k views

Create dictionary with default immutable keys

I've created a dictionary subclass with a set of default immutable keys. ...
7
votes
1answer
9k views

Python proper abstract class and subclassing with attributes and methods

The goal of the code below is to have an abstract base class that defines simple methods and attributes for the subclasses. This is part of an application that provides the code base for others to ...
3
votes
1answer
660 views

Subclass of socket with optional TLS

...
3
votes
1answer
80 views

Emulating super() in Python 3.x using Python 2.7

Depending on the name of the first argument, self.__sup or cls.__sup behaves like super() in ...
1
vote
0answers
134 views

AWS Redshift wrapper class that automates similar types of loads from S3

I have a AWS Redshift wrapper class that automates similar types of loads from S3 for me, and I have recently adapted it to work for Spark jobs, which don't require a manifest, and instead need a ...
1
vote
2answers
282 views

Class inheritance testing

I'm just messing around with class inheritance. I originally had a separate goal in mind but I ended up here, and my new goal was to have a parent that was completely ignorant of it's self, i.e. no ...
8
votes
1answer
995 views

Extending the functionality of lxml.etree

I wrote a class to slightly customize the behavior of lxml.etree.ElementTree and I use it quite extensively. It works great, but there are a few methods that I'm ...
3
votes
1answer
1k views

Object-oriented web scraping with Python

I usually write function-only Python programs, but have decided on an OOP approach (my first thereof) for my current program, a web-scraper. Here is the working code I wrote which I am looking to have ...
2
votes
1answer
8k views

Using a decorator to apply an inherited method to all child objects of the inherited type

I wanted to share this and get some feedback. My goal was to be able to have an object with methods: ...
3
votes
3answers
2k views

Logic Gate Simulator - Proper Encapsulation

So I was checking out the courses on InteractivePython, and I came across this example to demonstrate inheritance. My focus is on the Connector class and how it ...
8
votes
1answer
3k views

Creating instances of all subclasses in Python

I have a superclass with several subclasses. Each subclass overrides the "solve" method with some a different algorithm for estimating the solution to a particular problem. I'd like to efficiently ...
5
votes
1answer
569 views

Generic Pickle-Aware Super-Class for Mixing Classes with and without __slots__ in Python

I want a generic super-class that I can easily subclass - and if desired add slots to my class - without having to worry about any pickle issues (with the lowest protocol). Is this in general a good ...
4
votes
2answers
382 views

Performing calculations with a catalog of stars

The point of my code is to: Read in the observed data from the a catalog of stars (whitespace separated table). Do some unit conversions on the observed data (math stuff). Apply an interstellar ...
2
votes
1answer
265 views

Dumping fields from Python objects

I am writing a small class that has one method: get_state. It is parameterless and returns a dictionary of all the names in self (look in its dict) that are not ...
1
vote
1answer
71 views

How can I ensure some structure for classes for a plug-in system written in Python? [closed]

I have written a toolkit (hwrt) which has a plugin system. One type of plugin is a feature (see this) for many of them. There are some restrictions of feature ...
7
votes
1answer
187 views

Out of order class resequencer

I got bored recently and wrote a tool to re-order out of order classes in Python files. This can occur with some auto-generation code tools for databases and the like; these files can sometimes be ...
2
votes
3answers
5k views

Call method of specific parent class

This question is related to this topic. Context: ...
8
votes
3answers
12k views

Raising error if method not overridden by sub-class

Background I have a base (only 2 classes inherit from it, and only from it) abstract (meaning I don't want it to be used directly) class that implements some common functionality. Some of it depends ...
1
vote
2answers
1k views

Inheritance and forcing methods to be called inside another method [closed]

I've written a text parser that extracts useful information from a given text. Texts are formatted different, so there are different specialized parsers. I've designed them so that they all must ...