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
1answer
41 views

Difficulty understanding the Python data model and how built-in functions map to special methods

I have a Java background and am studying Python's data model. Specifically, I am curious about how and when special methods (e.g. __add__) get called. It seems like the Python interpreter may ...
-3
votes
0answers
53 views

Should I use an `else lif` or an `if` for the second of two consecutive assertions?

Here's an example of my question in python. Notice there's only a very subtle difference: changing an if to an elif. There's no difference in behavior; if the first if statement is executed, the ...
-1
votes
0answers
37 views

Which of these is a better practice to write Python unittest for CRUD operations of REST api?

I have a python class that has methods to perform the CRUD operations via REST api: class my_class(): def get_obj(self,...) -> requests.Response: res = requests.get(...); ...
1
vote
1answer
34 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 ...
-4
votes
0answers
13 views

Python app and docker server for quick machine learning prototyping

I'm currently developing an app using PySide2 for the GUI and PyTorch, scipy, and other libraries to process my data. However, I reached a point where my laptop is not being able to process the data, ...
2
votes
2answers
220 views

Loop complexity in C Vs Python

Just now I was reading a Python question on stack overflow, about clamping a list/array of results to be within a certain range. Once of the more simple answers suggested something like: ...
0
votes
0answers
52 views

Architecture Design of Command&Control application center for displays

I am facing dilemma on how to best design the following functionality. What design patterns and OOD principles should I use. For simplicity sake following are basic requirements: displays type ...
-4
votes
0answers
58 views

Reading and understanding badly written Python code 2 [closed]

I work in machine learning and a lot of my time is spent by taking others people code from github and testing their model or application. So I actually spend more time reading and running other ...
-5
votes
1answer
101 views

Reading and understanding badly written Python code 1 [closed]

I work in machine learning and a lot of my time is spent by taking others people code from github and testing their model. So I actually spend more time reading and running other peoples code, that ...
-2
votes
1answer
61 views

Is Python's Django WebFramework good to design Expert System as a Web App?

I hope everyone is good. Well, I am at the end of my degree BS (Software Engineering), and in the third Phase of my Final Year Project named as 'Test Phase'. My Project is to build an Expert System ...
1
vote
2answers
60 views

When using data and domain models, where should validation take place? And how should errors be fed back to the user?

When using data and domain models, where does validation take place? Both or just For example: class UsersDB(): def create(self, user_data): # Create user here return ...
-3
votes
0answers
38 views

How to publish a local website to a specific server?

I have a local website currently working perfectly that uses Plotly-Dash and a flask server. It may be terrible practice, but I have only 1 .py file (1000 lines of code) that contains all of my HTML ...
0
votes
1answer
93 views

Is it ever a good idea to enumerate a python range so you get the index twice?

Sorry for the weird title but I couldn't think of a better way to explain it. I saw someone do this once and didn't think it was a good idea but I wanted to check. Basically, he wanted to return the ...
1
vote
1answer
75 views

How should I approach the comparison of two BMP images?

I am currently writing a Python program that retrieves the pixels from two BMP files and finds the percent difference between them (without using the Pillow library for the purpose of learning). I can ...
-3
votes
0answers
42 views

Example projects for structuring & coding in large scale projects

TLDR Im asking for reference projects to look at to see where I can learn how to code + structure large scale projects (in python would be ideal). A detailed guide would be perfect, but I think those ...
1
vote
1answer
52 views

Should a REST API be used when a websocket is already open?

Background: I was working on a web-socket application integrated into a more conventional http request based website that uses REST APIs. Task: I need to retrieve user history from the database for ...
0
votes
0answers
88 views

How to design a fast way to `unarchive` file using python?

Assuming the following scenario: A python application that receives file and process that file trying to understand what the file format( any type of data/compressions/archives/packages/mounts/etc ),...
1
vote
1answer
62 views

Design Patterns for Passing Large Quantity of Parameters in Machine Learning

I am looking to better understand best practices for handling large quantity of parameters. I am particularly interested in the types of parameters involved in machine learning code bases and ...
2
votes
1answer
51 views

Machine Learning in Real Time

I've been going over some tutorials on machine learning using Python and libraries including SciKit Learn and Tensor Flow. (Basic tutorials like creating an algorithm to predict a price given input ...
0
votes
1answer
41 views

Double way parent child relationship in Django

I am building an app to register and update children information, this information is to be provided by their tutors. Every child can have multiple tutors, and a tutor can be a tutor for multiple ...
-2
votes
2answers
103 views

Python function name convention for “convert foo to bar”, e.g., foo_to_bar, foo2bar

I have a function that converts args given by argparse to a filename: def args2filename(args, prefix): filename = prefix kwargs = vars(args) for key, value in sorted(kwargs.items()): ...
1
vote
1answer
87 views

Implementing both Sync and Async clients with DRY

I'm developing a client library. I'd like to provide both Sync and Async interfaces to endpoints on a server. They would be rather easy to implement as completely separate entities, but I would like ...
1
vote
1answer
53 views

Flask restful file upload asynchronously?

I am working on converting an existing python based monolith solution to a microservice. The current flow is pretty straight forward: Accept XLSX as input -> Run some complex algorithms based on ...
4
votes
3answers
72 views

Designing interpretable/maintainable python code that use pandas DataFrames?

I am working with/writing a good amount of code in python using pandas dataframes. One thing I'm really struggling with is how to enforce a "schema" of sorts or make it apparent what data fields are ...
0
votes
1answer
73 views

Design decision of reading XLSX file at once or intermittently

I am working on converting an existing python based monolith solution to a microservice. The current flow is pretty straight forward: Accept XLSX as input -> Run some complex algorithms based on ...
-2
votes
1answer
126 views

Proper program structuring in Python

So, recently I have been doing a lot of programming in Python. I have noticed that my programs can be somewhat hard to read. I usually have one main class which does everything, sort of like this: ...
2
votes
1answer
157 views

Late inheritance, enforce subclass behavior in the future

A super class Transaction has two subclasses TransactionA and TransactionB. A Transaction is composed of multiple events that occur in time for a specific key (a file, a person, etc.). Depending on ...
-4
votes
2answers
36 views

Confused about AWS dev: How to use React with Python in my lambda functions?

I'm very new to the serverless and backend world. I've been looking at tutorials on youtube and on serverless-stack.com (which is really good btw) and they mostly seem to cover React frontend ...
-2
votes
1answer
63 views

Is this an example of a wrapper function?

I'm working on an application in python. One of the functions we have is called def createThread(user, status, title, ...): # some code here system.db.runUpdateQuery("INSERT INTO table(value,...
2
votes
4answers
213 views

Ahead-of-time compilation to native machine code of dynamically typed languages

It is my understanding that: It's particularly difficult to compile ahead of time, to efficient native machine code, a dynamically typed language like Python. Largely as a result of the above, the ...
0
votes
0answers
23 views

Python thermal live data processing

Looking for guidance on this topic, I have a fairly basic knowledge of python and very little experience working with live data. Currently attempting to work on a project that involves recording ...
0
votes
2answers
71 views

How do you handle abstraction when you have no control over the attribute class?

Python, has the library pathlib with the concrete class Path. I have a class called Cleanup, that looks like this: from pathlib import Path Cleanup: def __init__(self, source : Path, ...
0
votes
1answer
108 views

Single responsibility in python [duplicate]

The SOLID principle is supposed to be the underlying framework for object oriented programming. The "S" part stands for: "Single responsibility principle" which in wikipedia is defined as: A class ...
2
votes
5answers
112 views

Detect frequency pattern in a list of dates

I have a list of dates in which a certain event happened. Taking into consideration that a particular occurrence of the event can: Be a one time thing or Be part of a periodic series, which happens ...
-1
votes
3answers
164 views

Birthday Paradox, Analytical and Monte Carlo solutions give two systemically slightly different results [closed]

I was doing a Monte Carlo implementation of the Birthday Paradox in Python and I wanted to check if the results where the same as in the analytical implementation of the same problem (As they should ...
3
votes
2answers
87 views

Can Time be a Primary Actor in the Hexagonal Architecture?

I really like the fundamental principles behind the Hexagonal Architecture (Ports and Adapters) and I have mostly applied it to my system/application. There is one thing that I wasn't able to ...
1
vote
2answers
76 views

Python subclassed methods with additional arguments

Given the following structure where I want a method with a common name for each class, but each derived class needs an additional piece of information in order to form the appropriate result. ...
-1
votes
2answers
97 views

How to decide if a global variable is used inside or outside a function in Python?

In Python variables that are created outside of a function are known as global variables. However to create a global variable inside a function (a local variable), you can use the global keyword. My ...
-6
votes
1answer
93 views

While loop definition in python

My question is about a use of while loops that seems very abstract to me. I understand a while loop like the first one (one which has a clearly defined statement): num = 1 while num<1: ...
11
votes
1answer
588 views

Why was “self” chosen over “this” for the name of the first parameter of python methods?

What was the rationale for choosing the name self instead of this when defining class methods in Python? Yes, of course, you can name it whatever you want - but the widely agreed-upon name for the ...
-2
votes
2answers
60 views

Do python Objects also store their memory address?

In python documentation, I found that every object has a type, identity, and value. Does this mean that the object also contains/stores their memory address?? Or are they just created at some memory ...
0
votes
2answers
141 views

What is the reason python uses range in for loops?

Is there some philosophical reasoning behind why python uses this syntax: for x in range(1,11,3): instead of, for example, the BASIC syntax: for x = 1 to 10 step 3 If Python is supposed to be more ...
0
votes
2answers
105 views

Should parent classes define methods using attributes of child classes?

I need to extend the parent classes of two child classes by adding shared methods to them. Starting with the initial definitions of the child classes: class ChildA(ParentA): pass class ChildB(...
1
vote
3answers
161 views

what is the difference between Object and Value in Python

I have been trying to find this answer but I could not find the proper explanation Some say that they are the same and others say otherwise I know for a compound object, The object will consist of ...
-4
votes
2answers
98 views

How can I calculate the radius of an arc given by a series of points

Given a series of points, I need to assert that the plotted points form an arc (with a certain level of confidence), and I need to approximate the radius of the arc. For example, the following points ...
1
vote
0answers
63 views

Architecture recommendation for dynamic integration of algorithms/scripts

I am looking for a simple software architecture that is able to evaluate user data using different versions of algorithms. According to my concept, the user is able to upload tabular data via a Web ...
1
vote
3answers
100 views

Algorithm for random weighted boolean shuffles?

I don't exactly know how to phrase the thing I'm searching for in a succinct way, which also made it hard to research. In my application I need a random list of booleans, say of length five. The ...
2
votes
2answers
184 views

What is the difference between unit testing and handling exceptions

I have spent two full days now trying to understand the difference between unit testing and handling exception, but I can't get it. Things I have understood (or I think I have): Unit testing tests ...
-3
votes
1answer
143 views

How to make code runnable on open source code editors like Ace Editor?

For my computer science uni project I'm required to build a web application with an integrated code editor. I believe I can just integrate open source editors like Ace Editor. However, I feel ...
0
votes
2answers
82 views

Code style to keep track of nested objects and data types?

In untyped languages (Python, Javascript specifically) find myself making a lot of bugs / wasting a lot of time because I forget what's in the objects I'm passing around. For example, I forget things ...

1 2 3 4 5 33