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

Python flask app creating log files from pods

I have a flask app which reads logs from my kubernetes based on the environment product name and product type. I m creating the log files dynamically when a request arrives. If i choose a static ...
0
votes
0answers
14 views

Struggling to figure out how to write my application with MVC/MVA in mind?

I am trying to create a Sudoku game using Kivy and python 3.6. Right now I have a few Kivy screens to navigate between options and a new game, and one board that's set up and ready to play. My setup ...
2
votes
1answer
114 views

Access control to Django App running on private server

I am a self-learning programmer (with a fair share of python knowledge), and currently a company asked to develop a simple application so that they can track employee expenses (and I thought of using ...
-2
votes
0answers
69 views

When should I prefer `@classmethod` over a `@staticmethod` and vice versa?

Note: this question is not about "How can I use @classmethod and @staticmethod?" or "What is the difference between @staticmethod and @classmethod?" I need to store a dictionary ...
0
votes
1answer
1k views

What is a proper way to structure a Python project consisting of smaller packages that have shared code?

I have been debating this question internally for a few weeks now and I keep coming up short in finding a good answer to the question. I feel an example would be more descriptive than just talking ...
5
votes
2answers
3k views

How to create contracts in python

I am currently learning Python (from Java) and have a question on contracts. Example: an application defines an interface that all plugins must implement and then the main application can call it. ...
-3
votes
1answer
43 views

Achieving abstraction between persistence layer and business logic

I am writing Python scripts that regualary extract data from Databases (mainly SQL Server) using pyodbc. Until now I directly wrote my SQL Queries in the Source Code. However I want to clearly ...
-2
votes
0answers
22 views

Automating performance tests for python code in a CI

My apologies in advance for a question that might seem trivial - I am a mostly solo dev in academic environment and a lot of industry best practices don't necessarily make it here. Several of my ...
0
votes
0answers
23 views

Generating combinations with constraints (for graph generation)

I am trying to generate all possible graphs with n nodes and k edges while respecting some constraints (e.g., minimum and maximum degree allowed for a node). This is equivalent to generating a list of ...
3
votes
1answer
892 views

Separate business logic from ORM models in SQLAlchemy

I have a Flask application with tens of complex models, almost all of them related to each other. A simple pseudo-schema of some of them: +----------------+ | FoodGroup | +-------+--------+ ...
0
votes
0answers
49 views

Initializing instance variables from json file

I have a class whose instance variables should be initialized from a file ('settings.json'). That file does not always exist or is sometimes not filled with useful values, so I have to check for that ...
0
votes
1answer
254 views

Parameters vs Specialized functions

Trying to figure out which structure is cleaner between using a specialized function or using parameters to accomplish the same thing (see code example below). Essentially, I can reduce the number of ...
-2
votes
0answers
25 views

Designing an extendable software project template: reducing complexity

I set out to create a script for initialising software projects. GitHub templates are cool, but after using one, all names and project links must be changed. I wanted to have a few dialogs to fill in ...
2
votes
1answer
145 views

Optimal Simplification of Transposition Products

I am looking to take a product of a large number of transpositions, and boil it down to a smaller number of products. I have the following code, and would like some input on efficient ways to boil ...
-3
votes
3answers
73 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
79 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 ...
0
votes
4answers
275 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?
-2
votes
0answers
26 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
50 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 ...
3
votes
3answers
1k views

How to perform consistent hashing on any Python object that works with hash()?

I have a Python library that performs a kind of calculation given a parameter-object. A requirement of the parameter object is that it be both hashable and serializable. It's a long calculation, so it ...
3
votes
4answers
901 views

How to best encapsulate features in code and enabling/disabling them at runtime?

I would like to be able to abstract each feature developed by the team in a way that it can be enabled or disabled at runtime by using a distributed shared configuration system. Features are small and ...
-1
votes
0answers
39 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
2answers
461 views

Method object creation in Python data model

I've been reading the article on the data model of Python on its Reference website, and have been confused about this part: When the attribute is a user-defined method object, a new method object ...
0
votes
1answer
44 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 ...
-2
votes
0answers
66 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
41 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, ...
4
votes
6answers
2k views

What makes Python more used as an implementation language than the others?

Perl and Python are often compared to each other (let's not forget Ruby), and almost always those discussions will come to the conclusion pretty much anything you can do in one or the other. Without ...
2
votes
0answers
1k views

How to improve the detection of Probabilistic Hough Line Transform?

I'm trying to detect a clock hand in a video of an analogue display and extract the value it points to. I'm using Python with OpenCV for this. What I essentially do is: I'm using a Gaussian Blur to ...
2
votes
1answer
91 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 / ...
2
votes
3answers
173 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 ...
-1
votes
1answer
57 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 ...
30
votes
4answers
95k views

How to deal with database connections in a Python library module

I have created a library in Python that contains functions for accessing a database. This is a wrapper library around a third party application database, written due to the fact that the third party ...
0
votes
2answers
70 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 ...
23
votes
3answers
11k views

Are exceptions for flow control best practice in Python?

I'm reading "Learning Python" and have come across the following: User-defined exceptions can also signal nonerror conditions. For instance, a search routine can be coded to raise an exception ...
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 ...
-1
votes
2answers
165 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 ...
25
votes
2answers
59k views

Classes vs. modules in Python

Python has many modules (such as re) that perform a specific set of actions. You can call the functions of this module and get results, and the module as a whole has an idea behind it (in this case, ...
1
vote
3answers
142 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
45 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 ...
0
votes
2answers
113 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
3answers
135 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 ...
6
votes
7answers
768 views

I order my Python imports by name length. Does this make any sense?

First of all, yes I'm aware of PEP8 and the alphabetical method. I do sort my imports first by the PEP8 recommendation: standard library imports related third party imports local ...
2
votes
2answers
129 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
105 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
87 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. ...
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 ...
5
votes
2answers
714 views

Automated testing of programs with graphical output

I am a lecturer for a post-graduate module where I expect my students to write Python code that replicates examples from the textbook. The project has been running for a couple of years and this year ...
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 ...
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 ...

1
2 3 4 5
36