Skip to main content

All Questions

2 votes
1 answer
131 views

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
0 votes
1 answer
239 views

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
1 vote
1 answer
314 views

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
  • 153
0 votes
0 answers
86 views

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
-2 votes
2 answers
1k views

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
  • 153
1 vote
2 answers
90 views

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
0 votes
1 answer
207 views

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
  • 111
9 votes
3 answers
6k views

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
2 votes
0 answers
69 views

How to interface with very badly written code in Python? [duplicate]

I have to extend some very badly written Python code (no documentation, very interdependent, barely any encapsulation, very static, everything hard-coded, etc..) and therefore do I obviously have to ...
PPP's user avatar
  • 29
0 votes
1 answer
63 views

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
  • 2,266
0 votes
1 answer
71 views

Redesign factory to throw error on load time instead of on execution time

I am using a factory pattern to get objects that shouldn't be instantiated other than the factory class. These objects are of type ViolationType, which represent violations on a set of rule. Here is ...
dabadaba's user avatar
  • 2,266
1 vote
2 answers
157 views

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
  • 31
8 votes
3 answers
2k views

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
  • 227
8 votes
2 answers
4k views

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
  • 201
2 votes
1 answer
438 views

Python Classes and Design Questions

What is the best way to design a class to see if an update occurs on a property? I have a whole bunch of classes, and current am going through a re-design of the python package I created. ...
code base 5000's user avatar

15 30 50 per page