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.

Filter by
Sorted by
Tagged with
2 votes
1 answer
71 views

How do I structure my functions (and classes?) which interact with my Database/ORM?

So I am working on my first project using SQLite and SQLModel as ORM. Creating and handling the first table in my database was easily structured: A function for each CRUD-Operation. But now I have ...
Jan's user avatar
  • 201
1 vote
2 answers
78 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 ...
Tunahan's user avatar
  • 21
0 votes
0 answers
30 views

Endpoint design for single and bulk requests

I'm working on a project in Python and want to get it hosted for others to use, the internal recommendation has been to host it on AzureML (it is a non-machine learning model, but follows the same ...
evaless's user avatar
12 votes
3 answers
2k 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 ...
JSBձոգչ's user avatar
  • 1,440
1 vote
0 answers
39 views

Managing environments in a FastAPI app using Docker

Bit of context: I'm an Economics major that somehow ended up developing an API that's becoming a whole software project, so please bear with me. So, after I got asked to add logs I noticed I should ...
Juan C's user avatar
  • 111
1 vote
2 answers
257 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: ...
User051209's user avatar
1 vote
1 answer
149 views

Design patterns for long chains of computations in python (functions vs classes?)

A recurring pattern which I see in my code is chaining together a lot of functions. This is the result of a large number of processing steps needed for a given task. This could be e.g. a data ...
Jan's user avatar
  • 201
1 vote
3 answers
196 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 ...
merovingian's user avatar
0 votes
0 answers
40 views

Splitting a data set for CNN

Suppose, I have a tensor tfDataSet as follows: data3d = [ [[7.042 9.118 0. 1. 1. 1. 1. 1. 0. 0. 1. ] [5.781 5.488 7.47 0. 0. 0. 0. 1. 1. 0. 0. ...
user366312's user avatar
1 vote
2 answers
56 views

Hierachy and API design for a CSS-selector-related Python library

I'm writing a Python CSS-selector library that allows one to write these kinds of expressions in Python as a pet project. The goal of the library is to represent selectors in a flat, intuitive and ...
InSync's user avatar
  • 111
3 votes
2 answers
143 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 ...
Raspberry Intern's user avatar
3 votes
2 answers
518 views

How can I nicely pass on a class instance in python?

I am rewriting a streamlit app that is an interface to a laboratory management system (LMS). This means, that I have to make a lot of requests to that LMS through its python library (PyBIS). The way ...
Jan's user avatar
  • 201
-1 votes
2 answers
100 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,...
rmcsharry's user avatar
  • 117
0 votes
1 answer
93 views

Storing Data For Consumption in Python

I have a program which needs some constant data, in JSON-like format. However, this data only needs to be consumed by my Python program, and by making it Python code, I can include types like datetime....
pigrammer's user avatar
  • 111
-1 votes
1 answer
102 views

Best-Practice for organizing properties in a python class [closed]

When using properties in a Python class, you have a lot of boilerplate code. Is there a best practice to hide the code for the getters and setters? I know about @dataclass, but the problem is mainly ...
allo's user avatar
  • 178
24 votes
6 answers
7k 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: ...
Nikhil Kumar's user avatar
0 votes
0 answers
50 views

How should I organize build instructions for third-party packages?

In my projects I have several third-party Python packages which I need to build from source (because there are no .whl packages published for the versions+platforms I need). Currently these packages ...
oliver's user avatar
  • 111
6 votes
3 answers
2k 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 ...
str31's user avatar
  • 71
6 votes
1 answer
337 views

Matching dependency versions across multiple Python projects

I have about 60 repos containing Python packages, currently using setuptools in a setup.py (run via pip install) to manage third-party dependencies. Most of these packages need to be installed on a ...
Jason C's user avatar
  • 453
-2 votes
4 answers
302 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 ...
jason's user avatar
  • 15
0 votes
0 answers
27 views

How to show type introspection in UML

I'm modeling a part of Python/Qt GUI code which uses reflection to construct a collection of widgets, in a form. The code works like this: There is a Model which has attributes of various types, ...
Daniël Schenk's user avatar
0 votes
2 answers
147 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 ...
intern_2004_uk's user avatar
1 vote
2 answers
203 views

Best practices for unit testing when breaking down functions into smaller ones

Say we have a function of the form def func(num: int) -> int: num = num + 1 num = 2 * num num = num**3 return num and let us act like each line is a long computation so that we ...
grebs's user avatar
  • 29
0 votes
0 answers
52 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 ...
Marcel Wilson's user avatar
0 votes
1 answer
132 views

What are the performance implications of using multiple threads versus single-threaded [closed]

What are the performance implications of using multiple threads versus single-threaded asynchronous programming in Python 3.9? I've been working with Python for quite a while and I'm familiar with ...
user avatar
-1 votes
1 answer
83 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 ...
Thomas Vanhelden's user avatar
0 votes
1 answer
138 views

Automatic detection of semantic versioning based on Python type hints

I am the maintainer of a Python library that uses semantic versioning. Skip the next paragraph if you are familiar with what it means. The rough and dirty explanation of semantic versioning is as ...
JMU's user avatar
  • 9
0 votes
1 answer
131 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 ...
Alexander Soare's user avatar
-1 votes
2 answers
257 views

Should this code be made testable? [closed]

My code looks roughly like 40 def send_pubkey( s: socket ) -> None: 41 '''Transmit own public key unencrypted.''' 42 ...
Vorac's user avatar
  • 7,099
2 votes
1 answer
145 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, ...
Amir Hosein's user avatar
2 votes
2 answers
153 views

How should I structure an update script that handles the output of another module?

I have a large (>1,000 LOC) Python ETL script - call it fetch_and_transform_data.py - that fetches data from a remote database, appends the raw data to a local table, does some transformations and ...
Josh Friedlander's user avatar
0 votes
1 answer
126 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 ...
HerpDerpington's user avatar
3 votes
1 answer
390 views

Is C usually a last resort?

I've been learning C recently. I've completed a number of coding challenges on websites like codewars in C, and I always find myself wishing I had something like Python's flexible data structures. In ...
Connor's user avatar
  • 149
3 votes
2 answers
246 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 ...
PythonForEver's user avatar
0 votes
0 answers
111 views

Abstract base classes and mix-ins in python

In the python docs, I read this about the ABC (abstract base class) meta class: Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class. I don't come ...
henryn's user avatar
  • 101
0 votes
2 answers
641 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 ...
g00dds's user avatar
  • 111
3 votes
2 answers
246 views

Best approach to microservice shared databse architecture

I have two microservices, one Flask (python) and one Spring (java), they currently share a database. The Flask microservice handles processing json files (~40mb) for each user (could be 100's or 1000'...
MSmith's user avatar
  • 31
0 votes
2 answers
216 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(...): ... ...
James Lin's user avatar
  • 199
1 vote
4 answers
801 views

Dependency injection using method injection vs constructor injection

Where should I inject the dependency when I write a class? Should it be given to __init__ or to the specific method that uses the dependent object? Take the below two pieces of code for example, to me ...
alson_y's user avatar
  • 31
1 vote
2 answers
325 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(...
Scarabee's user avatar
  • 121
-1 votes
1 answer
58 views

Efficient way to write test cases depending on a Micro service

I'm very new to microservice architecture. In the Monolithic app structure, it was pretty straightforward to write test cases since everything was in one app. I have a situation where I manage a ...
Koushik Das's user avatar
0 votes
0 answers
81 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 # ...
winter's user avatar
  • 101
0 votes
0 answers
63 views

Data producers and consumers: How to connect MySQL with microservices?

Consider a web-app with 5 micro-services deployed with Docker, and a MySQL container dedicated to storing data produced from other services (shared-database pattern). How should I make the connection ...
JrCaspian's user avatar
  • 125
3 votes
4 answers
306 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....
Happy Green Kid Naps's user avatar
0 votes
1 answer
226 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
3 votes
1 answer
175 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 ...
Chewers Jingoist's user avatar
0 votes
1 answer
150 views

Where should research and production code reside in git?

We have research code that consists of Jupyter notebooks and large data files. At the same time, we also have production code that consists of Python source and CloudFormation templates. There is ...
Chewers Jingoist's user avatar
0 votes
3 answers
546 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 ...
Mathias A.'s user avatar
12 votes
2 answers
2k views

Designing a Python string validation library

My employer has a significant number of company-internal strings which require format validation. For instance, order number AAA-BBB-CCC, stock number AB-123456 or factory ABC1 - Regex with extras (...
MikeFoxtrot's user avatar
0 votes
1 answer
101 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 ...
CrazyProgrammist's user avatar

1
2 3 4 5
40