As of May 31, 2023, we have updated our Code of Conduct.

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
0 answers
19 views

Layout of python source code structure for a project that both exposes an API as well as applications [closed]

I have just inherited ownership for a smaller Python project. The project currently implements a set of command-line (CLI) applications related to data management at an organization. It also ...
chriss's user avatar
  • 1
2 votes
2 answers
128 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
63 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
328 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
229 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
53 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
68 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
  • 11
3 votes
2 answers
134 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
139 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
325 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
194 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
48 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
61 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
56 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
245 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
212 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
133 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
126 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
158 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
77 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
210 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
183 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
  • 311
-1 votes
3 answers
169 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
250 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
367 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
236 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,545
2 votes
2 answers
191 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
240 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
156 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
  • 13
0 votes
1 answer
154 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
331 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
177 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 ...
Matheus Dias de Souza's user avatar
0 votes
1 answer
100 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
167 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
171 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
  • 11
0 votes
0 answers
97 views

Python Typechecking versus TypedDicts?

From what I understand from this answer, it is not possible to use a typeddict and typechecking in a function. So for example, if one has a function: def some_func(some_int: int, some_dict:...
a.t.'s user avatar
  • 225
5 votes
4 answers
418 views

Is it better to iterate over data once and do multiple complex operations, or to iterate multiple times with simpler operations?

Here I'm working in Python, but it's more of a language agnostic question, unless specific language features makes it clear that an option is better than the other. I get my raw data from a REST API, ...
L'Animal Fou's user avatar
3 votes
4 answers
498 views

How to avoid code duplication when else and except are the same?

A simplified version of my code looks like this: def process( object ): try: if suitedForA( object ): try: methodA( object ) except: ...
Jann Poppinga's user avatar
1 vote
1 answer
246 views

How to handle i18n on a microservice architecture project?

I'm currently developing a bot for Discord that sends news over webhooks to multiple servers and I've decided to separate that news onto it's own microservice because the bot runs multiple instances ...
Blastcore's user avatar
  • 151
1 vote
1 answer
97 views

Strategy for deploying code internally and externally with common code base, but different functionality

For one of my current projects, written in Python, we would like to have two different versions: One for internal use, with all features enabled, and one for external use, with limited features. The ...
arc_lupus's user avatar
  • 121
3 votes
0 answers
72 views

Confused about how to test Python scripts that install and configure a development setup on OSX (VMware? Docker-OSX?)

In my company we hire engineers for various "disciplines"—iOS, Android, Web, Backend, Data, etc. Engineers follow an onboarding workbook to install what they need for their discipline. iOS ...
Andrew Cheong's user avatar
-1 votes
1 answer
55 views

Is it practical to cache multiple instances of variable API data (updates hourly for each instance) for N users?

I'm using flask with SQLAlchemy on a postgresql database for a mobile app I'm building. My application allows a single user to save lets say up to 5 different locations which are saved in the database....
joepaji's user avatar
1 vote
1 answer
227 views

Does "happy path to the left edge" break Python conventions?

I found the short article Align the happy path to the left edge quite helpful in improving readability of functions. Briefly, reading down the left edge of the function should step you through the ...
lofidevops's user avatar
1 vote
2 answers
112 views

Using class attributes as globals in Python - is there a catch?

I have found myself in the habit of using code like this. class glb: "just for holding globals" args = None # from argparse conf = None # from configparser def main(): ......
Alias_Knagg's user avatar
0 votes
1 answer
162 views

Should SSDP be considered as a go-to option for local network discovery in software development?

I am currently working on a Raspberry Pi based robotics project that I would like to connect to a realtime customized control panel/dashboard, mostly for debugging purposes. I created a test setup ...
Stathis91's user avatar
1 vote
1 answer
97 views

Should a LoggingHandler log?

I wrote a custom log handler that has a config file and uses a service on the network. Now I'm wondering if it should itself log. Pro: Everyone should log, it helps track errors, especially when you'...
Jann Poppinga's user avatar
0 votes
1 answer
71 views

UML design for data analytics of aggregated Survey Data

First and foremost, let me say that I do not have a Software Engineering background . I need help from the community as I have been assigned to create a UML (Unified Modeling Language) design from ...
user3115933's user avatar
3 votes
1 answer
506 views

In Python, why are variables defined in a compound statement not local to the statement?

I come from C++ background. One of the things I enjoyed was having a small scope for variables defined in compound statements such as a loop. In Python, compound statements do not form a block and a ...
AlwaysLearning's user avatar

1
2 3 4 5
40