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
-1
votes
0answers
17 views

Is this a good approach to stop an API function and return relevant error message?

I am writing an API function using DRF where I want the API execution to stop if it fails in any of the steps and return an appropriate response. So I created a custom exception which takes an error ...
0
votes
1answer
64 views

Designing a library API to allow for interactivity

The application I'm currently working on is deeply coupled to the UI framework in use (Qt at the moment). I would like to separate the UI-specific code from the rest as much as possible, with the goal ...
-2
votes
0answers
23 views

Selection of independent variables in K means clustering among a vast dataset

As I understand it, the process of K means clustering takes a set of sample points with k arbitrary centroids and uses Euclidean distance to classify the points closest to centroids to k groups. What ...
-3
votes
1answer
46 views

How do you use ad hoc polymorphism/function overloading with functions in Python?

So, let's say you've got a function foobar() which can function with a variable number of parameters inputted into it, and has different behavior for each of them. How do you get this to function ...
0
votes
4answers
235 views

Do all dynamically typed languages not support function overloading?

I have noticed that JavaScript and PHP and Python do not support function overloading. Do all dynamically typed languages not support function overloading? If the answer is yes, then why is that?
-1
votes
0answers
38 views

Can entities in Clean Architecture use boundary objects?

Let's say that we are working on some kind of school management system and we want to drop (remove) a course from a particular student during the enrollment process. We might have an enrollment entity ...
-3
votes
0answers
33 views

Problem with creating pyQt5 app

I'm hoping that someone can help me out. I've made a box that contains a raspberry pi and some relays. It takes in readings from pH and ORP sensors and I'm almost at the stage where it's running the ...
-2
votes
0answers
61 views

Python HTTP tunneling

Suppose a conjuncture where is needed to pass a normal TCP/IP traffic through a HTTP server, like the below scheme: Client <> SOCKS5 proxy <> HTTP server <> Remote First, the client ...
-2
votes
1answer
39 views

Use 1 to many relationship on same model or split it into two different models?

I'm building a forum application using the Django web framework but I'm not sure how to design the entity relationship diagram when it comes to the Post model. Since one Post can have many replies, ...
2
votes
1answer
85 views

Selective method inheritance

I have a lot of classes that are just a CRUD interface for microservices. They only have a param for the endpoint and some of the methods get_list / get_item / create / update / delete / activate / ...
-1
votes
1answer
50 views

Will conversion of a string to a list, and vice versa count in time complexity?

Assume that there is a question where a string needs to be passed. Some modification needs to be done on the string and then returned back. For the programming languages like C where a string is a ...
1
vote
3answers
163 views

Are user-callable recursive functions an anti-pattern?

I have a function in python that calls itself recursively, and has some internal variables passed down the recursion using keyword arguments (that are not listed in the docstring) Is it a problem to ...
0
votes
2answers
68 views

Is there a common Python pattern for the scenario “run code, save the output and load it on a rerun”?

I've been using different ad-hoc variations on this, especially in numpy / pandas / data science-y applications. For example let's say I've done some intensive processing that outputs a numpy array ...
0
votes
0answers
34 views

Pipeline pattern for MVC based GUI application?

I've got an application that uses MVC to run individual, isolated scripts to support our office. There is a root application will open new windows (limit 1 per tool) for each tool opened and each ...
-2
votes
0answers
27 views

Manage Single consumer with multiple producers in Python

I have an event bus that collects AI predictions from different sources (~100-200 sources). It means we have around 100-200 different producers. An other service is responsible for retrieving events ...
-1
votes
0answers
75 views

use of decorators in Python to provide default function arguments

Background I have been using Python for a few years now, but I only recently started to consider the use of decorators to reduce redundancy. Specifically, I started to replace default arguments across ...
-1
votes
2answers
162 views

How do you unit test methods with hard/impossible inputs to hardcode?

I have the following problem. I have a method which takes two other custom objects to work. This objects are required by the method because they have the information that the method requires to ...
1
vote
3answers
140 views

When is Model/View/Controller Too Much?

To preface, I work at a place that I feel misunderstands and overuses MVC, but I also recognize that maybe it's me who doesn't understand it. I'm used the model/view exclusively within the context of ...
0
votes
0answers
41 views

HTTPS headless browser to HTTP localhost Flask

I have two Docker containers: Headless browser grabbing images by running JavaScript Flask server analysing these images (and sending results to another server) I'm using a bridge network to ...
2
votes
3answers
134 views

When does a function violate the SRP?

I have a function that was written because several methods used the same sequence of code so an abstraction was useful. The function takes a string representing the path to a registry key and then a ...
0
votes
2answers
112 views

Loop outside method or method with internal loop?

If I have a list of objects that need to have an operation performed on each, is there a best practice in abstracting the loop or not? Looping over list and call def func(item): some_op(item) ...
2
votes
2answers
125 views

How do you unit test functions split in smaller functions

The problem is the following, suppose we have this functions: from PIL import Image from magiclibrary import perform_some_operation, stack_images def load_image(path: str): if isfile(path): ...
0
votes
2answers
101 views

Which is the best data structure to use when you want to randomly pick elements & use them, but also delete them after use

I have 1000 lines in a text file. I want to read them into some data structure[DS]. After reading them, I will be randomly picking 50 lines from the DS (using a Random Number Generator). Next time 50 ...
1
vote
1answer
86 views

Using isinstance() during exception handling for subsequent action

I've read various posts that polymorphism should be used instead of isinstance, and I agree that makes sense when the use of isinstance is checking the subtypes of a class to determine what to do. ...
0
votes
1answer
43 views

Design suggestions for my simple data-analysis program

I need to create a program with the purpose of cross-referencing personal info from a spreadsheet(s), to check for conflicts of interest between clients of 3 different law firms. All of this client ...
0
votes
0answers
47 views

Python: signals-based high performance communication system

I am working on a python framework for building a special kind of editors (so they have GUI) and I just split it into backend and a frontend (distinct libraries), s.t. another frontend could be ...
3
votes
4answers
213 views

Python access properties via public or private interface?

I work with Python classes that define properties that return some privately managed data member. When accessing this data in the body of other methods, is it better practice to use the public or ...
1
vote
1answer
58 views

Improvement of the config file management

I am working on a personal project for more than 6 months now, this project is composed of three distinct parts, simulation (wrapping a software), database related stuff (store the simulated data in a ...
0
votes
1answer
64 views

Python: Function pipeline with multiple return/input values, or use OOP? Best Practices?

I have a 'processing' function and a 'serializing' function. Currently the processor returns 4 different types of data structures to be serialized in different ways. Looking for the best practise on ...
6
votes
1answer
123 views

Handling same exception thrown by different methods

Is there an idiomatic way to catch an exception when multiple methods may throw?: try: someMethod() # raises OSError someOtherMethod() # raises OSError except OSError: handle() The ...
4
votes
1answer
131 views

How do you perform accumulation on large data sets and pass the results as a response to REST API?

I have around 125 million event records on s3. The s3 bucket structure is: year/month/day/hour/*. Inside each hour directory, we have files for every minute. A typical filename looks like this: ...
-1
votes
1answer
65 views

Is it better to pass self or the specific attributes in Python methods?

I'm trying to understand when it is better to pass explicit arguments to a method and when it is better to just pass self. I created a little example to illustrate the question. Here are two different ...
1
vote
1answer
78 views

Is bytes as request parameters as rest endpoint a security risk?

I am working on an application where user can send in an absolute path of an image or URL as string in API endpoint. My code is able to handle that. Now I have been asked to add the code which can ...
1
vote
2answers
100 views

Alternative to using regex in Python

Background I do programming with Python and now and then i run into a situation where i have to use regex Typically i try to learn a bit about it and look at examples of doing things similar to what i'...
0
votes
1answer
60 views

Recommended way to use a python backend from a c#-application

I have an old windows forms gui used to control a custom measurement system. Originally, it handled acquisition, calculating, database handling and presentation of measurements. Now, because of some ...
-2
votes
1answer
46 views

Best practice: keep DB models in one file or split into modules?

I've a Python project with ~30 SQLAlchemy models and I'm not sure where they belong. All models belong to the DB but also to a module, so I'm not sure about the right namespace. Here are some ideas: ...
29
votes
10answers
7k views

What is a good approach to handling exceptions?

I have trouble reconciling "best practices" and real-world approaches to handling exceptions. In my day to day routine, I find myself running into the following examples: try: ...
6
votes
3answers
235 views

Is there a better way to run sequential tests?

I'm using unittest framework to run Python tests. Some system tests consist of a series of steps for a given scenario, and they need to run in a specific order. For example, I have a client ...
0
votes
0answers
18 views

How to Structure a Python API Poller + Computation

I am writing a program which polls a website every minute for updates on the weight of various types of widgets(A, B, C...) If Widget_A is returned I will: Download the accompanying timestamped PDF ...
-1
votes
1answer
95 views

Python generating payload and parsing payload

(Using python) I am looking to generate a bytes (or can be string that I convert to bytes) that is a message to send over TCP. The format is [Header][Length][Payload]. Within [Header] is a [...
1
vote
0answers
46 views

What's the best way to build a Flask API to control and show the status of a program tool I have built?

I've developed a backend project using Python. It collects data from different sources, process the data, and then perform actions with it (for example, store relevant info in a database). To execute ...
0
votes
0answers
65 views

What design pattern is Python's PEP 451 implementing?

PEP 451 provides a mechanism to change what is actually loaded when someone uses import in Python. After reading PEP 451 and using it in one of my projects I thought that this was an implementation of ...
0
votes
1answer
57 views

Best way to migrate to new versions of librairies with breaking changes

(I orignally posted my question on StackOverflow and figured maybe this would be a better place to ask) I provide details on the librairies I'm working with because it helps understand my issue but it ...
-3
votes
1answer
81 views

Good idea to use source control with my Lambda functions?

So, I have this legacy project I am starting to hump into with my team. This is a AWS Lambda Python application (a bunch of Micro-services that inform various front-ends). So, when I asked how they ...
0
votes
0answers
23 views

DJI tello edu- Path planning & barcode scanning for inventory management

I am a computer science student required to develop a drone for inventory management (barcode scanning) as part of a warehouse management system. The system will require the drone to fly autonomously ...
1
vote
0answers
39 views

Securing Arbitrary Code

I need to run arbitrary code snippets in Python and Javascript on a server. It cannot be run in the browser. I'm thinking of sandboxing the code in an AWS Lambda serveless function. However, I'm ...
0
votes
0answers
32 views

Better way to define & load custom modules?

I have a project that would benefit from having a module folder where classes can be dropped in and automatically loaded. Thus, I have: . ├── main.py └── modules ├── __init__.py ├── one.py ...
0
votes
2answers
80 views

What is best practice for getting a variable passed into a function several layers deep in a local function call?

I have a situation as follows, I have a relative path that I want to get for a directory. The directory structure is as follows, Windows Folder Structure C:\FileFolder\LowerLevel\ThirdLevel\script.py ...
2
votes
3answers
183 views

How can I avoid chasing my own tail when testing against complicated return values?

Sometimes there are functions that return complicated data and cannot be divided any further e.g. in the area of signal processing or when reading and decoding a bytestring to another format. How am I ...
0
votes
3answers
207 views

Is it really good practice in Python code for machine learning to use so many parameters?

Currently I am a student learning Machine Learning, and so my observation is from an academic context. It may be different in a business environment. One thing I find very odd when I see Python code ...

1
2 3 4 5
36