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

merge two api data in one object python [closed]

Check this page https://my-json-server.typicode.com/typicode/demo Here you will find two api’s one for posts and comments https://my-json-server.typicode.com/typicode/demo/posts https://my-json-server....
-1
votes
1answer
71 views

How would I detect a physical attack in video form? [closed]

I hope this question isn't too vague because it's more a discussion than a question. I want to write a code which can detect physical violence in a scene (with the end result being the prediction of ...
1
vote
1answer
69 views

legacy refactor and churn

I am trying to work on finding the following metrics New Work - totally new code which does not replace other code. Churn - code that is rewritten or deleted after being written Help Others - where ...
1
vote
2answers
232 views

Communication between two apps

I am thinking of creating two applications, one of which (App 1) will be in Django (DRF) and other (App 2)might be Django but might be another more lightweight framework (maybe Flask or plain Django ...
-3
votes
1answer
80 views

How to know how much RAM & CPU my script reqire? [closed]

as the title, how to know? is task manager the best way as my friend told me? I code in python.. I'm new here sorry if my question was in the wrong place.
0
votes
1answer
91 views

How to write tests in TDD for downloading and unpacking a file?

So I want to write this function that downloads a file and unpacks it in python using TDD. The function will look like this approximately import urllib.request import tarfile def download_and_unpack(...
0
votes
1answer
104 views

How encrypting website data works

If i wanted to encrypt a password on my website before its sent to the server, would i have to encrypt the password in javascript on the frontend for it to be hidden over the interent or could it be ...
-1
votes
1answer
50 views

Generator variable can’t be used more than once [closed]

Python loop generator Looks like I’m missing something with for loop generators… I deliberately made this simple code to test what was happening when I converted my list comprehensions to generators. ...
2
votes
1answer
54 views

Python inheritance: how to check the closest abstract parent class?

I'm dealing with two categories of machine learning algorithms. For simplicity, let's call them A and B. There are multiple concrete algorithms in each category, and my goal is to implement all of ...
-2
votes
1answer
62 views

How to pre-enter a user input() in Python? [closed]

I am interacting with a 3rd party program that will request 2 user inputs to start running a process. I know what they are going to be and want to preempt them, so that I don't need to enter them ...
0
votes
0answers
15 views

How to build a chatbot that is Open Domain but can intervene on specific intents?

As per my knowledge, there are 2 type of Chatbots- Open Domain and Closed Doman Intent Based. I was wondering how are conversational agents created such that can converse as if they are Open Domain, ...
0
votes
0answers
71 views

Correct structure of a data science project: keeping as functions versus object-oriented framework

I'm working on a data science project that involves data ingestion, cleaning and various aggregations and functions of timeseries equipment data primarily using Pandas. I began the project just ...
1
vote
1answer
78 views

Dealing with business logic on DTOs using a DDD

I have a scenario in which an Entity defines an EntityRepresentation that is created from another end. The EntityRepresentation is a value object that implements some logic that should be performed on ...
1
vote
0answers
31 views

Looking for the right design (pattern?) for my webapp and external APIs intgerations

I'm working on a simple CRM (Customer Relationship Management) webapp (Flask and Peewee ORM) and I found myself in a situation where I believe that I should have used a design pattern that I may not ...
0
votes
1answer
108 views

Using the same function in two classes? [closed]

I have two classes for making pyqt5 windows. Inside class one I have a button with a function it is connected to. Class One: from PyQt5 import QtGui, QtWidgets, QtCore from PyQt5.QtWidgets import ...
0
votes
0answers
58 views

Multithreading vs Asynchronous game loop for multiplayer online game?

I'm trying to create a turn based multiplayer online game where players can be grouped in a room/lobby and play (similar to Ludo but number of players can be more than 4). There can be multiple such ...
0
votes
2answers
411 views

How can Python, a language that supports Object Oriented Programming, be implemented in C, which is not an Object Oriented Programming language?

To my understanding, C does not have the concept of objects, then how can Python be implemented in C to support something that C can not? How is the concept of "Object" modeled in C? What is ...
-1
votes
2answers
66 views

Are there any advantages to using dockerfile dependencies over virtual environment for Python apps?

I am currently working solo on a very small simple python microservice. I started building this app, mostly by habit, in a virtual environment. As I started to get closer to the point where deployment ...
2
votes
2answers
88 views

Dynamic loading of objects defined during development for a running system

So I have a design/architectural question. I want to develop a pattern in a programming language that is able to allow a app command-line shell to send commands to a running application to create ...
1
vote
1answer
54 views

Imposing an object interface in Python

I wanted to implement a method insertCard in Python which interacts with only a specific type of object called a Card. The Card should always have a cardId and may have additional payload or fields ...
0
votes
1answer
56 views

How to structure Python modules so they are accesible from different submodules

This is somewhat similar to this question but I could not find a solution there. I have a project that I've worked on over the past 4 years. I started without any Python knowledge and learned as I ...
1
vote
1answer
70 views

How to organize ORM models and business logic

I have a Python application using SQLAlchemy. It uses around 15 database tables. For example, I have an image table that lists image files manipulated by the application. Most operations involving ...
0
votes
0answers
19 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
2answers
68 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
54 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 ...
-2
votes
4answers
103 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
81 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
1answer
58 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 ...
1
vote
4answers
322 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
1answer
42 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
96 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
96 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 ...
2
votes
3answers
179 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
135 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
35 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
171 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
143 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 ...
2
votes
3answers
144 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
118 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) ...
3
votes
2answers
136 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
108 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
92 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
46 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
49 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
214 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
65 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
66 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
160 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
138 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
2 3 4 5
36