Skip to main content

All Questions

2votes
1answer
131views

A Design Pattern for a component which both writes to and reads from an ordered event log

I am searching for a good design for a set of components I am writing for a system. I believe it is very likely there is a Design Pattern, or set of Design Patterns, which could be combined to solve ...
user3728501's user avatar
1vote
1answer
314views

Where to create repository instances?

I've several repositories. To make them testable, I add the ORM session in the constructor. class Repository: def __init__(session): self.session = session def save(object): self.session()...
Mr. B.'s user avatar
0votes
1answer
239views

How do we nest decorators?

It is possible to nest many decorators. @decorator_one @decorator_two @decorator_three @decorator_four def some_silly_function(): pass How do we write a decorator class so that the order in which ...
Samuel Muldoon's user avatar
-2votes
2answers
1kviews

Best practice: keep DB models in one file or split into modules?

I've a Python project with ~30 SQLAlchemy models and I'm not sure where they belong. All models belong to the DB but also to a module, so I'm not sure about the right namespace. Here are some ideas: ...
Mr. B.'s user avatar
9votes
3answers
6kviews

Better conditional debugging pattern?

Given the need to log only in debug mode the easiest way would be to use if conditions: def test(x, debug=False): if debug: print(x) # ...Some more code if debug: print("...
Veneet Reddy's user avatar
0votes
0answers
86views

Download method of type void vs response

Given a method that is widely used and has a void return type: from somepackage import download_model from somepackage import get_filename def download(name, download_path): response = ...
Yosi Dahari's user avatar
8votes
2answers
4kviews

how to refactor many singletons

I have a medium-sized python program (~5000 lines of code), which I've built up over time, with no particular plan as I went ahead. The architecture I've ended up with consists of 5-6 large Singleton ...
funklute's user avatar
15votes
6answers
13kviews

What is the simplest human readable configuration file format? [closed]

Current configuration file is as follows: mainwindow.title = 'test' mainwindow.position.x = 100 mainwindow.position.y = 200 mainwindow.button.label = 'apply' mainwindow.button.size.x = 100 ...
Juha's user avatar
  • 303
8votes
3answers
2kviews

Refactoring of a client API for avoid duplicated code and unclear passage of parameters

I need to develop an API, the functions of the API are requests that call the service exposed by a server. Initially the API worked like this: class Server: def firstRequest(self, arg1, arg2): ...
k4ppa's user avatar
0votes
1answer
207views

Passing messages through a chain of containers in python

When I write python code for simulations, I often end up with the following situation: I have a class describing the general environment which contains a list of instances of a class that describes ...
user68044's user avatar
1vote
2answers
90views

Building a plugins-based code in Python

I have a program which perform different actions depending on the plugins that are passed. For example, python main.py -m foo -m bar will perform the actions of foo and bar. The structure of the ...
user avatar
1vote
2answers
157views

Critique on design principle and validity of such in general

I was hoping you could give some feedback on an idea I had for designing functions. I am trying to think of a unifying principle for choosing what functions should return. The specific project is ...
Handcre's user avatar
11votes
2answers
6kviews

Caching factory design

I have a factory class XFactory that creates objects of class X. Instances of X are very large, so the main purpose of the factory is to cache them, as transparently to the client code as possible. ...
max's user avatar
  • 1,115
5votes
1answer
4kviews

How to design a composite pattern in Python?

The concept I'm programming an interface over pygame as a personal project, to make the creation of games easier for me. So far I managed to design an architecture that behaves like this : Objects ...
Zoé Martin's user avatar
0votes
1answer
63views

Method grouping other methods of the same family and how to call any of these separately

Worse title ever but I don't really know how to describe my scenario in a line... So I have a method that wraps the calls of a many methods of the same nature. Once any of these methods have finished,...
dabadaba's user avatar

153050per page
close