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

OOP - Is this data hiding?

I've been reading about data hiding and there seem to be slightly different definitions of it, so when trying to come up with a practical example, I'm not sure if I'm doing the right thing. So far, I ...
2
votes
2answers
65 views

Having tasks that can be ran individually or “in trees”, and each task can be blocking or non-blocking

I'm creating a framework that needs to execute certain tasks, I'll use building a car as an example for this. So, an individual task could be something like weld metal or screw bolt. But there are ...
0
votes
1answer
76 views

How do I test a method which interacts with a database?

So I have a database class which has methods dedicated to specific actions. For example I have below method which accesses and writes to a table in the database: def trackUserPerformance(self, ...
0
votes
0answers
18 views

SQLAlchemy with Plain Old Python Objects (POPO)

In SQLAlchemy class models are of data type Column which contain metadata about the table in the database. Such as: id = Column(Integer, primary_key=True, autoincrement=True, nullable=False) When I ...
1
vote
1answer
35 views

Ideal architecture for ML training -> API service workflow, with multiple models/services? [on hold]

I'm planning to construct a workflow/environment for training and serving NLP classifiers, that follows something like: The model training system takes in annotated documents from a subset of a ...
0
votes
3answers
120 views

Should the attributes of a class be part of the public interface even when they could break its methods?

As a minimal example, consider the following (in Python): class Foo: def __init__(self, bar): # Assume bar is a valid at this point self.bar = bar def divide_by_bar(self, num)...
-1
votes
3answers
254 views

How to write code to write code? [closed]

I am working on a flask backend / vue front end project where the gist of it is a bunch of CRUD screens. What I've been thinking about doing but have never done in practice and want to know how to do,...
2
votes
0answers
73 views

Object attributes as special parameter objects in python

I am writing a library that can be used with some GUI and would like to be able to build an interface where user can see and/or change most of the object's parameters, and also write some of these ...
1
vote
1answer
46 views

Designing an Entity Component System for interfacing with a scripting language

I am currently building an Entity Component System (ECS) in cython in order to speed up operating on large numbers of game objects in python. In the process of building this system, I ran into the ...
1
vote
1answer
90 views

Python - Paradigm to compute different formulas with the same function

I have different equations to compute the same quantity. For example, val = my_func(a, b, c) but also val = my_func(x, y), where my_func represents the quantity I would like to compute: it could be ...
0
votes
0answers
34 views

Maintaining data: Unprocessed data, processed data, and results from processed data

I have built a python process which automates some portion of handling support tickets in Salesforce. I use selenium to extract all open support tickets and stores them in an archive. From that list,...
1
vote
2answers
242 views

Exceptions versus guard clauses

I'm trying to get my head around Python exceptions. I've read quite a bit on the topic but can't get clear answers to some questions. In particular, I'm still not sure whether to use exceptions or ...
0
votes
1answer
34 views

Should i use a separate droplet(DO) for the API?

I have a little app(PHP) that uses data from a third party. That data is processed constantly and saved into a database. And now i want to create a RESTful API to allow access to that data. Should i ...
0
votes
0answers
60 views

Generating fake number for a 25 digit PII number in a file containing millions of rows

I have to expose some sensitive data containing a PII column that has a 25 digit number. Rest of the columns aren't PII data. This is done such that the data can be safely shared to the larger ...
-3
votes
1answer
148 views

Why constructor inheritance is not supported in Python? [closed]

Consider the case where I have the following classes, class A: def __init__(self): print("Class A") class B(A): def __init__(self): print("Class B") b = B() The expected ...
0
votes
3answers
142 views

How can we make a UML diagram (or something similar) for a project which doesn't contains classes (like non object oriented)?

I am working on a python project and I didn't use classes but created different modules and added functions in them. Now I need to draw a diagram to describe the project/application for a paper. I ...
-1
votes
1answer
257 views

What is the programming paradigm when I just use functions in a file to organize my program?

I'm programming a telegram bot with Python and, for a number of reasons, there are no classes in the whole project, just several functions correlated to the the file where they are located. E.g., my ...
1
vote
2answers
67 views

Unit conversion of input to/output of public functions/methods

The question/s I'm working on a small scientific Python package. Many of the public methods it is going to offer will have to deal with dimensional input. A wavelength, for example, which could be ...
1
vote
0answers
94 views

Implementing an iterator vs. looping over a list

I want to loop over a number of rows in a database and I have implemented an object in order to access the rows. Now when using this object I am not sure about the best practice. Implementing an ...
2
votes
1answer
31 views

Setup pipeline to analyze data stored in web app DB

Background: So there is a (Ruby) web app with a production Postgres DB (hosted in the cloud) I would like to run some machine learning algorithms in a Python setting on the production data and (...
1
vote
1answer
28 views

Most readable way of generic views placement

What are your suggestions on placing many generic views? Let's consider a classic situation where I have many generic views for CRUD for given models. What is the best way to place them in views.py? ...
1
vote
2answers
95 views

Architecture for RESTful API and a web admin

I am trying to build a RESTful API (using Flask) that will be later consumed by a mobile application. I also have a requirement to build a Web Admin. The Web Admin will have functionality that will ...
0
votes
3answers
100 views

Options for parsing input that will include math

I'm working on a program that takes in user input which often includes things like math.sqrt(), imaginary numbers, multiplication, division, and similar (basically, standard math plus imaginary ...
1
vote
0answers
45 views

Extensible / Plugin Architecture in Python - overwriting methods deep in the inheritance tree?

Current situation I'm developing a test-framework in python for end-to-end tests for a large ERP application. The AUT (application under test = ERP system) is structured in modules and provides a lot ...
0
votes
2answers
109 views

Which is better approach - using subprocess vs communicating over socket?

I have been working on a python project for sometime which has been structured in following manner: We have a function like this: def execute_cmd(cmd): (out, err) = subprocess.Popen(cmd)....
0
votes
0answers
35 views

Neural Networks object creation from OOP perspective [duplicate]

Let's say that I have a class representing the Neural Network. The neural network is composed of three bigger units: a subpart_1, subpart_2 and subpart_3, being called in such a way, that the output ...
2
votes
3answers
315 views

How to deal with configuration files that are becoming too complex

There is a db with tables of genes. And these genes would need to be annotated based on the client's needs. So if a gene matches condition x, then add a new column y and value z to that gene. Every ...
1
vote
1answer
68 views

How to avoid confusion with possible referenced before assignment when it won't be (Python) [closed]

I have some code equivalent to this: state = True if xyz: state = False try: value = foo() except: handle_exception() state = False if state: bar(value) On the last line it will ...
0
votes
1answer
42 views

Combining web app and CLI to python package

I'm writing a program in Python that has two different entry points. There's a CLI that processes some data and needs to be installed to run hourly on a server, this populates a database. There's also ...
1
vote
1answer
30 views

Django - should I create related objects immediately or on demand?

Let's say you have a ForeignKey MyModel.related_model and this related_model has all fields either null=True or default=something. Like User.userprofile which I use on several places in my project. ...
-3
votes
1answer
92 views

Pythonic way of writing `for my_var in my_iterable` [closed]

A very common pattern in python is: for something in ['an', 'iterable']: func(something) I almost always see the iterable as a list (like in this example), but it could very well be a tuple, set,...
-4
votes
4answers
128 views

Creating one function for multiple purposes vs multiple functions for one purpose each [closed]

I have one function that is used to compute distances of an object in 3 different ways. Is one of the following two methods considered better practice: Creating 3 different functions, one each for ...
15
votes
6answers
3k views

How to implement float hashing with approximate equality

Let's say we have the following Python class (the problem exists in Java just the same with equals and hashCode) class Temperature: def __init__(self, degrees): self.degrees = degrees ...
0
votes
0answers
38 views

Querying the domain model

Background: I am working on a document classifier which needs to classify document based on some keywords. The list of keywords and the category is provided as the configuration parameter. The ...
0
votes
1answer
56 views

How do I save user data in a file and populate the GUI/Software based on that file?

So I'm developing a GUI that consists of many widgets such as checkbox, buttons, radio-buttons, combo-box using Python Qt5. This GUI is to perform some calcualtion based on user choices. I'm trying to ...
0
votes
0answers
70 views

Should I repeat unnecessary else condition? [duplicate]

I would like to know what the best way is for dealing with a situation where I repeatedly check a condition within a function using an if-elif-else chain, and if the condition is else, I raise an ...
1
vote
2answers
60 views

Balancing function call overhead and testability in a code that is a part of the deep learning model training loop

I am currently implementing the transformer architecture for sequence to sequence problems. Key part of the model is the attention mechanism, which is basically a matrix multiplication, followed by a ...
0
votes
1answer
174 views

Lazy assignment of python variables

I have the following if statement and I feel it could be made simpler to read by breaking the terms up into their own named variables. if os.path.isfile(os.path.join(dirname, 'file.json')) \ or (os....
12
votes
3answers
2k views

Working through the single responsibility principle (SRP) in Python when calls are expensive

Some base points: Python method calls are "expensive" due to its interpreted nature. In theory, if your code is simple enough, breaking down Python code has negative impact besides readability and ...
1
vote
1answer
89 views

Using semantic version with trunk based development for Python package

I am trying to understand trunk based development with semantic versioning for a Python project. Has anyone had any experience of adopting a trunk based development with semantic versioning for ...
0
votes
2answers
147 views

What is the definition of implementation in programing languages? What is CPython?

I came across this word "implementation". CPython is one of the most common implementations of Python. What exactly is an implementation? I researched a bit on how a Python code runs. First, it is ...
0
votes
0answers
59 views

Passing Python Class to CLI arguments

So i want to make a crawler in python but not the usual UA/middlewares way. My idea was a modulable architecture, which pass the callable class as arguments in a cli. This is kind of odd, i don't know ...
0
votes
2answers
62 views

Is it worth to use a sql db for just two columns (possibly extensible)?

So, first of all hello to everyone, I hope you are having a good day :) I will give you a little context. I coded a program for my job, in which I save to a database Errors ID and their solutions. It ...
2
votes
1answer
71 views

Best practices on testing a function based on third party service

I'm trying to figure out how to create unit tests for a function, which behavior is based on a third party service. Suppose a function like this: def sync_check(): delta_secs = 90 now = ...
1
vote
3answers
212 views

What is a good method/practice I can employ to keep identical code snippits in two places in sync? Also, help documenting functionals

If I could get some input on the design of this, I would be grateful as well. Note that I'm programming in python. There's a function F that takes lots of data, runs some analysis on it (taking ...
1
vote
2answers
123 views

Observer reporting to multiple layers up from the bottom of hierarchy

There is a swarm of objects. When a new unit of certain kind appears on the frame, the swarm integrates this object by calling some add_new_unit method. Above the swarm is a controller abstraction, ...
4
votes
2answers
105 views

Pandas based visual data cleaning tool

I am looking to build an web-application which would allow user to upload csv file - see preview of few rows in the file and then apply different cleansing and standardisation rules. For example the ...
-4
votes
1answer
156 views

Running python script in a node server? [closed]

My younger brother has made a small rock, scissor and paper python game running in console. I want to host it on my own domain, running on a digitalOcean droplet. I have no more experience with python,...
1
vote
2answers
92 views

Python method docstring: to use or not to use Args: Returns:

Default docstring from PyCharm automatically creates template with Args: and Returns: sections. However I have observed that this prompts people to say obvious things, frequently just stating the ...
0
votes
1answer
118 views

Is the complexity of this code quasilinear time?

Algorithm explanation: based on an unsorted list I want to find the indexes of the values in another sorted list. Note that all values are unique and the two lists have the same values, only in ...