Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-2
votes
0answers
15 views

How do someone parse this in python? [on hold]

I don't know how to parse cpu, memory_mb, and a print("CPU: " + r["message"]["vminfo"]["cpu"]) ^that is something i did
1
vote
1answer
59 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
156 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
104 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
62 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
74 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
72 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
101 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 ...
-2
votes
1answer
45 views

Given list of sets, find set of elements which belong to at least two different sets [closed]

Given a list of sets S, I'd like to find a set of all elements which belong to at least two differents sets in S. Here are my attempts in Python: import itertools duplicates = set() for u, v in ...
4
votes
1answer
69 views

Maintaining parallel libraries: Binary files access + Metadata Database ORM design

I'm dealing with a higher-level data abstraction that I would appreciate some input on. I'm working on an application that uses a large data lake. The data lake is consisted of thousands of large ...
-2
votes
1answer
49 views

Montoring website for Job scheduling software [closed]

I have a job scheduling software that uses Unix cron for scheduling a job. Unix Cron takes care of launching a Job process at a specified time. Each run of Job has a key (job_name and a date) ...
-3
votes
0answers
13 views

Qt.QApplication.setGraphicsSystem substitute for PyQt5

I am using a python script for GNU radio which is using PyQt4. My gnuradio is having PyQt5. Since setGraphicsSystem is no longer there in PyQts, what can be the substitute for Qt.QApplication....
-3
votes
2answers
107 views

What is the best way to run untrusted hooks/plugins?

I'm building a data processing system where users can submit hooks to execute on incoming data. The hooks are untrusted and should execute in a sandbox with access only to a limited API that I expose ...
0
votes
1answer
53 views

Python - Type Hinting specific sized Vectors

Considering a class method that takes a "vector" (Tuple or List of either int or float) of defined values such as the following: import sys from numpy import isnan, array, float64 class Shape: """ ...
0
votes
1answer
68 views

Should there not be methods intended to be only called from inside of the package, but from the outside of the class they're defined in?

Note: This is a follow-up to this question on StackOverflow. I have to write a wrapper in Python to an external API, accessible through HTTP. The code is supposed to be publicly available on GitHub. ...
-2
votes
1answer
65 views

method taking a class parameter

I have recently begun studying UML. All is going fine so far until I saw the following: This is a class Called Point2D It has 2 attributes which are x, type float and y, type float. It has 3 methods ...
1
vote
2answers
128 views

Python - Should a function write to a file or return text to be written?

Currently I have something like the following def writeThis(fileHandle, name): fileHandle.write('Hello ' + name) writeThis(fh, 'Alice') Something about this doesn't feel right however, it ...
-2
votes
1answer
67 views

Packages with only __init__.py - Possible issues?

Considering a Python Project structure such as the following, where there are "empty" packages with __init__ files simply pulling code from the lib folder: . ├── foo │   ├── fred │   │   └── __init__....
0
votes
1answer
85 views

Best practices for handling application specific exceptions?

Is it considered to be a good practice to convert all types of exceptions (exceptions from internal logic of application + exceptions from application's external dependencies - for example: File ...
9
votes
1answer
142 views

Importing Python modules at the time of use

Often in my own personal Python libraries, I do something like this: class MyClass: # ... def plot(self): import someGraphicsLibrary as graphicslib graphicslib.plot(self....
-1
votes
2answers
167 views

How do I extract only bold text from this image? [closed]

I am looking for an approach / algorithm for using OCR (like Tesseract) to extract only bold text from an image. The Python code I wrote can already identify small letters and numbers, but it cannot ...
1
vote
1answer
51 views

Declaring constants: one file or separate?

I currently have a small list (< 20) of constants that can be segmented into the following three parts: - main script (tokens, log file location) - database setup (username, passwords) - API (API ...
2
votes
0answers
52 views

Can/Should I make an automatic installation of new python libraries after a git pull?

Imagine the following situation: I'm working on a python project, and I install the library antigravity with pip. I add the function fly() which uses the library, and I commit and push the changes. ...
1
vote
1answer
42 views

Sharing Docstrings between similar functions?

Assuming we have different classes with methods that possess the exact same description, however execute code a bit differently for the same return type. class Foo: """This is the Foo class ...
0
votes
2answers
75 views

How to design classes of a self-driving machine, if I need a simulation?

Background: I'm working on a project with a self-driving machine with a tank-like control, somehting like: forward() left() right() stop() The code is running on a raspberry pi. The GPIO outputs are ...
0
votes
2answers
75 views

Are there any issues with having having the main data in an object's state?

class DataFrameAnnotation: def __init__(self, df: pd.DataFrame): self.df = df def transformation_1(self): self.df + 1 def transformation_2(self): self.df + 1 def main(self): ...
1
vote
1answer
80 views

Is using enums to filter attributes considered a code smell?

I was doing some reading here and one of the suggested answers states: In short: Don't try to decide how an object might react to some action from the outside, tell it what happened, and let it ...
2
votes
0answers
70 views

Is assigning a method in the constructor good practice? [closed]

Here's a class with a method that calls different functions based on a parameter set in the constructor: functions = { "arg1": f1, "arg2": f2, "arg3": f3 } class C: def __init__(self,...
-1
votes
1answer
24 views

python library for stdin stdout managing [closed]

I am writing a test in pytest for a software. This test relies a lot on console output generated by the software. The flow is something like: * start the program * send some commands to the program *...
-1
votes
1answer
81 views

time complexity for 3 foor loops different leangth [duplicate]

I have this method arr // input new_ seq = [] for i in arr: new_seq.append(i) __new_seq = [x for i, x in enumerate(arr) if x not in new_seq] for j in __new_seq: new_seq.append(j) ...
1
vote
2answers
135 views

How can I integrate Python code with c# code? [closed]

I want to integrate code python (hierarchical clustering algorithm) with code C#. (The idea of ​​the project is to divide similar people and put them into classes using the algorithm. We use language ...
0
votes
0answers
15 views

what's the proper way to interpret SREM results from REDIS

Background I am writing a REST API that exposes a method that allows the caller to delete a resource from the REDIS database. Because I'm using a SET, when you try to do an SREM, it will just return ...
0
votes
1answer
33 views

WebApp for ETL with visual mapping - read csv and map it to data model

a few years ago I wrote a python script for reading CSV, handling the headers, filtering data, renaming stuff via RegEx...bascially to do various ETL stuff. This was done using a exhaustive ...
3
votes
2answers
130 views

Design pattern for similar classes that require different implementations

Edited: Update is at the bottom There could be a common or best practice for this scenario, but I am unfamiliar with it. However, it could very easily be a matter of subjective opinion on how one ...
-1
votes
1answer
69 views

Making the REST API to act as a playlist

Imagine the application I am building as a normal media playlist (Video / Music). On the client side, I select the files I want to play (Files are located on server), and I send its paths to the ...
0
votes
2answers
184 views

How compatible are data science notebooks with clean architecture?

Clean architecture decouples an app's core from the presentation/UI layer. The UI is just a plugin, replaceable (eg, web-based to desktop) without impacting the core. Many data science apps mix code,...
0
votes
1answer
43 views

Abstracting a set of services behind a common interface

Yay or nay? I have several related but separate services that are to be run in different processes. They execute a particular task unique to the service. Their call signature is similar, but the name ...
2
votes
2answers
71 views

Designing a Python API with defaults

I'm designing an API for a Python library. The user will create objects with several parameters. In most cases, the user will either leave these at their default values or will set them globally, for ...
28
votes
6answers
2k views

Turning a personal Python project into a releasable library

I'm an academic rather than a programmer, and I have many years' experience writing Python programs for my own use, to support my research. My latest project is likely to be useful to many others as ...
1
vote
3answers
179 views

How can I resolve this **kwargs antipattern?

I am a hobbyist programmer, working on a much more complex Python project than I've attempted before, which is in the form of a Python library. I find that I'm often passing **kwargs around (as ...
3
votes
3answers
317 views

What is the safe way of using keyword-only arguments?

Keyword-only arguments are arguments that can only be supplied to a function by keyword. In Python they are defined by a single asterisk in a function's signature. For example: >>> def foo(...
3
votes
1answer
120 views

Why would CPython logging use a Lock for each handler rather than one Lock per Logger?

While developing my own logging library, I studied the source code of the standard logging module of CPython. One of its features is that handlers are thread-safe. One can write logs to a file from ...
-1
votes
2answers
43 views

“private methods” vs method out of class in a python module

I have a module with the class Foo. Foo has three methods: The constructor(__init__()) An error handling method (_error_handler()) The method that actually does something. (run()) Then, I have a ...
3
votes
3answers
144 views

refactoring function to have a robust design

i am having a simple app example here: say i have this piece of code which handles requests from user to get a list of books stored in a database. from .handlers import all_books from flask import ...
2
votes
1answer
97 views

How to organize my test functions?

I'm writing a software application of a few thousand lines of code (in Python), and in order to keep the whole thing together, slowly but certainly the need for unit tests (and later, other types of ...
0
votes
2answers
48 views

Setting up data for integration tests: using SQL queries or APIs calls

We a have test repo outside of the app repo and we can generate data by either having direct SQL queries or through API calls (http requests). We've been entertaining the idea of switching over to ...
0
votes
1answer
96 views

What determines the internal order of a Python set?

When I read about sets in Python, it is always mentioned that they return items in an arbitrary/random order. What exactly causes this "randomness"?
-1
votes
1answer
27 views

How to read user input and at the same time execute periodic commands

How would I go about prompting user-input, while at the same time running timers, to periodically execute automatic functions. Pseudo-code to illustrate: while true { if input() OR timer(10) ...
1
vote
2answers
59 views

Building a plugins-based code in Python

I have a program which perform different actions depending on the plugins that are passed. For example, python main.py -m foo -m bar will perform the actions of foo and bar. The structure of the ...
1
vote
2answers
76 views

CLI tool with overloadded structure

I have a python CLI tool that my department uses to process some excel file aided by a yaml. I tried to diagram a basic work flow here: Step 1: User downloads a xlsx, puts it in a file, runs tool --...