Questions tagged [python]
Python is a dynamically typed, high-level interpreted programming language. Its design focuses on clear syntax, an intuitive approach to object-oriented programming, and making the right way to do things obvious. Python supports modules and exceptions, and has an extensive standard module library. Python is general-purpose and thus used widely, from the web to embedded systems.
2,034 questions
3
votes
1
answer
220
views
How to structure repositories for a small number of entities?
I am working on a project implemented in DDD style, and I use Repository architecture pattern to persist domain changes. I have multiple roles in domain layer, and that's what raises my question - how ...
2
votes
3
answers
224
views
Which association should be in the class diagram
there are a vehicle class and customer class . In short, in the customer class there is a function that shows 'can this person or company rent that car'.The function uses a object of vehicle and ...
13
votes
3
answers
3k
views
Using `any` to indicate a wildcard value
I'm writing a validator class to validate certain request objects against a known format. Rule declarations and the validator will both be written entirely in Python, and I don't need to store the ...
2
votes
2
answers
2k
views
Why access the attributes of a Python class by reference?
Attribute references and instantiation
In this link, that is part of the official Python documentation, I have found the following information:
Class objects support two kinds of operations: ...
1
vote
3
answers
1k
views
What is more Pythonic way to handle try-except errors?
I have two different options in mind:
def foo():
try:
# do something interesting
except:
# report error here
return bar
bar = foo()
or
def foo():
# do something
...
3
votes
2
answers
187
views
Conceptual Software Design: Managing Large Number of LEDs with Raspberry Pi
Question Summary
I am writing a program that will run on a Raspberry Pi 4b+ designed to manage hundreds of LEDs, as well as a few other devices (such as small motors). This is for a project I am a ...
-1
votes
2
answers
151
views
Architecture for EOD (end of day) stock exchange prices
I need to work out the architecture for a NASDAQ frontend charting application (a desktop app in .Net). Note that this is NOT for real-time quotes.
NASDAQ provides an api that gives historical pricing,...
24
votes
6
answers
9k
views
Best practice for redundant conditions in if-elif-else statements
What is considered better practice?
Case 1:
if n == 0:
doThis()
elif n < 0:
doThat()
elif n > 0:
doSomethingElse()
Case 2:
if n == 0:
doThis()
elif n < 0:
doThat()
else:
...
6
votes
3
answers
3k
views
Best design practice when one python method passes most of its arguments to another method
My code has 2 python methods defined, m1 and m2. m1 receives 6 arguments - p1,p2,p3...p6. It uses p1 in its own code, but passes p2-p6 to m2. Is there a recommended programming style here to prevent ...
-1
votes
4
answers
738
views
Leetcode: 2327. Number of People Aware of a Secret and Problem with programming skill in general
On day 1, one person discovers a secret.
You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the ...
0
votes
2
answers
345
views
Build an API for a graph app with + 30 millions data points
I am quite new to design software and especially graphs. So I am working on a full-stack app with a back-end built on FastAPI (python) et front-end on React.
I need to create 4 graphs on a single page ...
0
votes
0
answers
60
views
Organizing screen resolutions?
Does it make sense to organize screen resolutions?
I write a lot of selenium tests, often which I need to choose a resolution for the browser. I ended up creating a dictionary with some of the more ...
0
votes
1
answer
373
views
Should you add the name of the package to the module/package name in Python? [closed]
I'm looking for some best practices for readability (and clean code in general) for naming modules/classes within more extensive projects. More specifically, is it reasonable to add the package's name ...
3
votes
2
answers
318
views
Should a decorated function know about its decorator from a semantic point of view?
In this toy example some_function is... some function that takes a dict as an input and modifies it in place somehow.
def some_function(dct: dict):
"""Do something to the items in ...
2
votes
1
answer
330
views
two diffrent database in unit of work
I will explain my problem in the form of an example.
Suppose we want to use both databases in a transaction.
Data is edited in database 1 (for example, Postgres) and then added to database 2. Finally, ...
0
votes
1
answer
709
views
What's the best way to import a python module in a python module without cluttering the modules namepace? [closed]
Let's say I am writing a python module module.py. Which provides functionalities for other parts of my code. Of course, the module has to import other modules. A simple example:
import abc as _abc
...
3
votes
2
answers
275
views
Abstracting constrained strings in serializer. Good or bad practice?
I'm using FastAPI and in my schemas (that is, serializers) I have something like this:
from pydantic import StrictStr, BaseModel
class Str255(StrictStr):
max_length = 255
# my schemas:
class ...
0
votes
2
answers
4k
views
How to terminate python queue and instruct all consumer-threads to finish their tasks?
I have a multi-threaded application.
There is 1 thread that produces a resource and puts it into a queue and many (not constant amount) consumer-threads that get the resources from the queue.
When ...
0
votes
2
answers
503
views
What is a good unit testing strategy against a chain of public method calls?
say I have this code which is a chain of public methods, public_c calls public_b calls public_a
def public_a(...):
...
def public_b(...):
...
public_a(...)
def public_c(...):
...
...
1
vote
2
answers
1k
views
Ordering keyword arguments in a function call
In some languages such as Python, the order of keyword arguments in function calls does not matter. But is there a best practice for it?
For instance, suppose that a function's signature is def foo(...
0
votes
0
answers
111
views
Access one usecase into another usecase
I am working on machine learning project. I use jupyter for quick prototying. Now I am trying to convert it into concrete python project using clean architecture.
entities/
- problem.py # ...
3
votes
4
answers
479
views
Reducing cyclomatic complexity of a state machine
I have a function (written in Python) that processes a loosely structured log file.
The log file would have begin-end markers for different sections, with each section describing different things (e.g....
4
votes
1
answer
293
views
What is the anti-pattern for modules that group objects of the same type? [closed]
In MVC, I often seen all models in a models.py module, all views in a views.py module, and the controller - you guessed it - in a controller.py module. In other projects, I sometimes see all exception ...
1
vote
3
answers
2k
views
How to handle dependencies between microservices all called within one large service
We are working on a suite of Python 'services' each of which is basically an application that does some calculations based on a domain (data) model and returns the results. These services are designed ...
0
votes
1
answer
138
views
Sending and receiving results from microservices
I welcome everyone. I'm trying to understand microservice architecture.
The task such: is 2 services. The first - for example, books rooms in a hotel. The second is something like a console interface ...