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
7 votes
3 answers
1k 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
  • 73
-3 votes
0 answers
44 views

Advice on whether to build this program with PowerShell,Python or Javascript(Node)? [closed]

I have a website that plays a series of videos one after the other (think a playlist). I want to screen capture a recording of the videos. I have achieved this with: ffmpeg -f gdigrab -framerate 30 -...
Ralf_Reddings's user avatar
6 votes
1 answer
230 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
229 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
23 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
120 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
183 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
49 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
117 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
75 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
100 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
129 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
241 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,093
2 votes
1 answer
120 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
145 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
86 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
383 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
242 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
98 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
359 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
205 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
186 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
646 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
264 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
52 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
79 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
59 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
292 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
225 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
161 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
142 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
347 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
90 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 vote
1 answer
360 views

Storing multiple instances on a Singleton?

RefactoringGuru's example Singleton in Python has an _instances dictionary field class Singleton(type): _instances = {} def __call__(cls, *args, **kwargs): if cls not in cls....
Michael Moreno's user avatar
1 vote
3 answers
196 views

Is adding functions to a namespace/module after imports an anti-pattern?

In my python codebase I have several open source dependencies, eg. pandas, plotly, etc. Some of these are missing some functions that I'd rather they have. I sometimes add functions to these libraries ...
MYK's user avatar
  • 321
-1 votes
3 answers
224 views

Is it better to override methods in classes or make methods general?

I am creating the backend of a microservice that will serve as a tool to see in real time how the company's employees are distributed by projects and what days they have assigned to each one. The ...
Diegol's user avatar
  • 1
1 vote
2 answers
702 views

How to deal with constants that are shared between multiple packages?

I'm looking at creating my first packages to clean up my codebase. Below is a very simplified version of my current project structure: my_project/ |-database.py |-app_1.py |-app_2.py |-constants.py ...
Jossy's user avatar
  • 311
1 vote
2 answers
426 views

Software Design: Decoupling when highly dependent on a third party library

As part of an university project I am currently working on an eeg-biosignal classifier. While the project itself doesn't really focus on design ("anything that works") I am trying to learn ...
J. Lo's user avatar
  • 21
1 vote
3 answers
244 views

Are interchangeable types a security vulnerability? Are they good vectors for attack?

Suppose you are given a python API: def onArgumentReceived(x): doWhatever(x) # expects a unicode string I am not a security expert by any stretch of the imagination, however on the face of this, ...
Anon's user avatar
  • 3,575
2 votes
2 answers
211 views

Design pattern for constructing and linking up objects that form a graph

I am working on a simple library that will help me work with prescription drugs. For instance, DrugBank contains a list of FDA approved drugs, and, importantly, how these drugs interact with one ...
Pavlin's user avatar
  • 149
3 votes
3 answers
249 views

Is there an approach to keep a large number of conditionals maintainable

I work on a survey that has a lot of questions. This means we have a lot of columns/variables to work with. This translates to a lot of conditionals that have to be done a certain way according to a ...
SunflowerLuau's user avatar
4 votes
2 answers
2k views

Raising new exceptions in Python backward-incompatible?

I'm trying to know if we can freely raise new exceptions when maintaining methods of a versioned library. Here is a minimal example of what the change could be: import logging def check_id_old(...
Stéphane Bruckert's user avatar
0 votes
2 answers
163 views

Encoding text to image and decoding back to text

(FYI: I asked this question on stack overflow and was directed here) My problem is as follows: I have a dashboard running on a server at customer premises which updates every 15 minutes The dashboard ...
Imtiaz's user avatar
  • 23
-1 votes
1 answer
184 views

How can I use builders for products with incompatible interfaces?

I am working on a program to automatically design heater units based on varying client specifications. The process for creating each heater is quite involved and requires multiple optional steps ...
JS Lavertu's user avatar
0 votes
2 answers
539 views

Is there a better way to trigger API calls from an on Prem SQL Server without using a job scheduler?

I'm not sure if this is the correct area to ask this question, quite honestly, I'm not sure how to phrase the question because I don't know if what I'm thinking is possible. I'm trying to figure out a ...
hnewbie's user avatar
1 vote
2 answers
200 views

String representation in Python runtimes

Python is one of the few languages to support a string data type of code points (Unicode Scalar Values). I'm also wanting to creating a language that has this same characteristic, but I need to ...
Hydroper's user avatar
  • 121
0 votes
1 answer
137 views

What is an apporpriate design pattern when dealing with Pandas and databases?

We're dealing with a lot of "data analysis", basically different sorts of data mangling, aggregations and calculations using Pandas. Usually, the data is time series data. All underlying ...
highviolet's user avatar
1 vote
1 answer
186 views

Elegant way to handle two options, when both is also an option

In the simplest case, I have some code where the user may want to do one thing (a), another thing, (b), or both (a+b). The options are reasonably complex and have their own functions, but I would like ...
QuantumChris's user avatar
0 votes
2 answers
219 views

Is there some easy way to refactor deeply coupled python code

I recently took on a long ago python project which has some weird code style that I can't pinpoint. e.g. # this is a params and value package? opts={ infile="xxx", outfile="xxx" } ...
zhang's user avatar
  • 111

1
2 3 4 5
40