Skip to main content

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
13 votes
4 answers
3k views

What side-effects, if any, are okay when importing a python module?

Generally, modules should not have side effects. However, in a lot of cases, the side-effects are hard to avoid or may be desirable. There are also popular packages with on-import side-effects. Which ...
Kaia's user avatar
  • 394
5 votes
2 answers
412 views

When the stack frames become computationally expensive

I've been experimenting with different data structures and algorithms in Python, Java and C to see in what circumstances function/method inlining could bring meaningful gains in terms of the execution ...
user1069483's user avatar
0 votes
0 answers
22 views

Structure for jupyter notebook to python module conversion

When working with AI models because of the long load times, I want do develop with juypter notebook. However, I want to release/publish as a normal python script. You can use the jupyter nbconvert --...
Tom Huntington's user avatar
0 votes
1 answer
96 views

Best practices for setting up a test suite for a python library?

note: here library means a package that is installed from some wheel/egg/tar file. as opposed to a regular package which is just a container of modules basically. package usually is used for both as ...
gnarlyninja's user avatar
0 votes
1 answer
134 views

Serving part of a web application as a python package for people to install, ok to do?

Background To preface, I am building a database for the construction of a timing detector. However, I am very new to software engineering and database development. I have been building a website using ...
jfwinston32's user avatar
1 vote
1 answer
119 views

Deciding between logic on the front-end or back-end

Before I begin, I want to say I am very new to this and I am a junior but also solo developer with no seniors to ask for guidance. Please feel free to explain to me that I am not approaching it ...
Zayd_MP's user avatar
  • 11
3 votes
1 answer
220 views

Object-oriented programming design with relational database tables

I want to understand what is considered best-practice to better align with OOP when handling relational databases. I cannot find any online examples where classes and a more maintainable/re-usable ...
Yannis's user avatar
  • 147
-2 votes
1 answer
110 views

Defining functions inside vs outside a class

Say I have a class with a function do_thing that is comprised of multiple steps, which themselves segregate into functions (first_process and second_process). At what point would this be considered ...
Tim Kirkwood's user avatar
0 votes
3 answers
190 views

Architecture to avoid circular imports in Python, specifically a flask server

I have a flask server which uses a controller-service-resource model. For simplification it is like this: Controller(parses requests, dispatches to A or B): ServiceA ServiceB However there are ...
VectorVictor's user avatar
2 votes
1 answer
124 views

Refactoring Processor classes

I am writing some python 3 bioinformatics software and was wondering about the best way to write it in an OOP format. I am pretty sure a lot of my classes are violating the SRP principle, but I'm not ...
Tim Kirkwood's user avatar
-3 votes
1 answer
111 views

Is it a bad idea to use NodeJS + Python for back end development?

I'm working on a platform that consumes and transforms data to make reports and visualize those reports in a client app. The team has experience with NodeJS and NestJS, and some of us have experience ...
Mats's user avatar
  • 1
0 votes
0 answers
30 views

Webapp/Webserver architecture patterns for shared components

Motivation: I am building a webserver that is essentially a dashboard app. Users make requests and get analytics data and visualizations back. Multiple users can be in the same "workspace," ...
StarFox's user avatar
  • 101
1 vote
2 answers
100 views

Dynamic web application hitting database on front page load to fetch profile image

Folks, I am in middle of writing a web application (Python/Flask) where home page has user profile image in the navbar which is coming from a database (blob), I am wondering if this is a good practice....
afsar's user avatar
  • 19
2 votes
2 answers
247 views

Should private attributes or public attributes be the default in Python classes?

In python we use a leading _ to make object attributes implicitly "private". If we want to give people set/get access we can use the @property decorator. Or, if setting/getting is allowed ...
Alexander Soare's user avatar
1 vote
1 answer
167 views

How does one add observability to python code without affecting code quality?

We're working an agile project and designing as we go on a new python commandline app / systemd service for some fancy in-house project. Right now, we're supposed to be adding an observability / ...
Peter Turner's user avatar
  • 6,915
-3 votes
2 answers
167 views

Polymorphism with variable default argument count

I'm in the process of writing a library in Python, and I've run into a design problem concerning the use of polymorphism. I have an ABC with abstract method 'foo': class A(ABC): @abstractmethod ...
Jan van Wijk's user avatar
1 vote
0 answers
125 views

How to structure your Python code with asynchronous and synchronous parts

I have a Python FastAPI server application which naturally guides you towards the asynchronous paradigm. For legacy reasons, I have to support two backends, one which is purely synchronous and one ...
user3058865's user avatar
-3 votes
1 answer
441 views

Better way to type casting an object from one custom class to another [closed]

I have one object, its class inherits all property from GUI class, that takes and some values and one function during instantiation, that handles click and upon receiving the click it calls the ...
novice's user avatar
  • 95
0 votes
0 answers
43 views

Best design pattern for integrating Google OAuth with existing JWT token-based authentication system

We currently have a backend authentication mechanism in place that utilizes JWT tokens. Users sign in or sign up using email and password, and upon successful authentication, the backend issues JWT ...
Samiksha Garg's user avatar
-2 votes
1 answer
140 views

Are there some best practices how to build a client library for an API?

I was tasked to create an API client library for our already existing API. I tried to research some ways how to approach this but couldn't find anything. Are there some best practices how to build ...
user3630290's user avatar
2 votes
2 answers
528 views

Is this architecture overkill? What is a good way to architect this software?

I have an algorithm I am trying to implement that has steps 1 to 5. There are several different ways I could implement each step. Each calculation step is essentially just an astronomy calculation, ...
Hunter's user avatar
  • 187
1 vote
2 answers
122 views

Using an instance method or a function with conditional logic based on type

I'm developing a data pipeline in Python. We receive a variety of different types of data set that we need to process (e.g. xml, json, csv and some Excel workbooks) - where processing involves parsing ...
henryn's user avatar
  • 111
0 votes
3 answers
98 views

Python API - store data in SQL AND NoSql

I am a student and am currently programming an API in Python. Among other things, it is possible to register, log in, create a user profile with data, etc. I would like to be able to store and ...
flo's user avatar
  • 1
1 vote
1 answer
84 views

How to test integration with an infinite generator

I'm struggling to (integration) test a component that makes use of an infinite generator. Background: At a really high level, this component is essentially a "middleman" in a kafka workflow. ...
Luke Nelson's user avatar
-2 votes
4 answers
823 views

Compare version numbers

I need to compare versions of a software. The requirement is that I need to know if a given version is older (smaller), same or newer (higher) than another one. The version format is XX.X.XX where: ...
Marcus's user avatar
  • 129
-1 votes
1 answer
122 views

How to structure a modular MITM proxy with python

To explain what I'm trying to accomplish. Sometimes I visit website1.com, here I can download Linux ISOs but it's a bit annoying because it has a lot of ads, some of which are launched via javascript ...
Daviid's user avatar
  • 49
-3 votes
1 answer
120 views

Learn a framework on a project, or mix languages between backend services [closed]

I am designing my next project, which will do various domain-specific tasks, but all that will be controlled and used via a generic crud web app. I have been professionally using Java with Spring for ...
rafal.sz's user avatar
7 votes
1 answer
2k views

Why are there two ways to retrieve values from a dictionary in Python?

In Python there are basically two ways to get a value from a dictionary: dictionary["key"] dictionary.get("key") Is there any - maybe historical - reason for this behavior? I ...
Thomas Junk's user avatar
  • 9,583
1 vote
2 answers
393 views

Splitting up large SQLAlchemy model

Anybody have advice on splitting up a large SQLAlchemy model into smaller parts? I have a ~2000 line model called Article that is becoming difficult to manage. We often have to scroll and scroll to ...
caseym's user avatar
  • 119
2 votes
1 answer
371 views

In python when is absolutely preferable use a class than a module?

Python is the language I use most in this period. My background in Java Before start learning Python I have programmed in Java language. In Java all code is written inside the methods of a class and ...
User051209's user avatar
0 votes
0 answers
61 views

How to structure my DB setup?

I have made a small project to try and learn to implement SQLite-DBs into my projects. For the DB part, I use sqlmodel and followed their tutorial. For the creation of the engine however, they use a ...
Jan's user avatar
  • 213
3 votes
1 answer
173 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 ...
lubitelpospat's user avatar
2 votes
1 answer
166 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
  • 213
2 votes
3 answers
145 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
  • 31
1 vote
0 answers
63 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
  • 11
13 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
2 votes
0 answers
264 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
  • 121
2 votes
2 answers
1k 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
2 votes
1 answer
188 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
  • 213
1 vote
3 answers
290 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
49 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
63 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
155 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
4 votes
2 answers
6k 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
  • 213
-1 votes
2 answers
118 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
106 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
437 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
8k 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
63 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

1
2 3 4 5
41