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.

-3
votes
0answers
23 views

What is python's equivalent to powershell dsc? [on hold]

I'm developing a test infrastructure where I need to configure the test machines in a particular way depending upon the project and then tear down and reconfigure it in a different way for different ...
1
vote
1answer
56 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
151 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
103 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, ...
1
vote
2answers
2k views

Python - best way to have interdependent variable in a class

Newbie Python questions: I want to model something that can have a several inter-connected instance variables and if I set one, I want to recalculate the others. Any can be set. E.g. a circle - each ...
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 ...
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. ...
3
votes
4answers
1k views

Convention for writing Python without newlines or whitespace?

Is there a convention for writing Python when deprived of newlines and whitespace? For example, stackexchange comments, Twitter, text messages...
-4
votes
1answer
73 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
71 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 ...
0
votes
1answer
273 views

Django Fat Models: Where should I put model creation logic?

I'm reading Two Scoops of Django 1.11. At 7th chapter it introduces "fat models". It says that best practice is to put a big part of logic into the model and keep views as thin as possible, but then ...
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 ...
29
votes
6answers
23k views

Programming language usage at Google [closed]

I have heard Google uses Python, Java and C++. But what I don't know is how is each of those programming language is used. I mean what is Python, Java and C++ is used for at Google. Why would they ...
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 ...
7
votes
4answers
1k views

Why do textbooks use pseudocode rather than real languages?

In colleges and in algorithm textbooks, it is quite common for the teacher and author to explain control flow in pseudo-code. With the advent of more expressive languages like Python and Haskell among ...
-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 ...
-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....
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: """ ...
-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 ...
-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
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 ...
1
vote
5answers
1k views

Call a script over the network

I have a Python script on a box that I want to call from a Java server, over the network. I know that I can start a server on the Python side and then connect to it from the Java site, but I am trying ...
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 ...
5
votes
2answers
2k views

Scheduling: balanced home/away round-robin tournament algorithm

I am trying to achieve a round-robin algorithm for sports scheduling that also guarantees a fair or balanced home/away rotation. I based my algorithm on the round-robin scheduling algorithm: def ...
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 ...
3
votes
2answers
3k views

Python Import Order

I am working on a large project in python that has lots of imports. Some imports are system imports - these are easy, usually just absolutely imported. Some imports are third-party. These can have ...
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

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): ...
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 ...
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 *...
10
votes
4answers
1k views

Why do python generators and functions share the “def” keyword?

Consider the following: def some_function(): return 1 def some_generator(): yield 1 In the code above, some_function is a function, while some_generator is a generator. They look quite ...
24
votes
2answers
5k views

Why is universal newlines mode deprecated in Python?

I just noticed that the universal newline feature of file operations seems to be on its way out. The documentation for Python 3.5 open's mode parameter indicates that it's deprecated: 'U' ...
-2
votes
2answers
2k views

Algorithm for scheduling shifts

I am trying to write a program to help scheduling shifts for the employees of a small business. There are 28 shifts that needs to be assigned to 28 employees (so this means that each person gets a ...
0
votes
1answer
921 views

Is there a way to control a looping Python script with Heroku?

I have a Python script that continuously makes GET and POST requests to a third-party API at about 1 request per second. It uses a while loop, so the requests all come from the same process. Currently,...
-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
134 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 ...
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 --...
15
votes
5answers
7k views

Algorithm for flattening overlapping ranges

I am looking for a nice way of flattening (splitting) a list of potentially-overlapping numeric ranges. The problem is very similar to that of this question: Fastest way to split overlapping date ...
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 ...
-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 ...
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 ...
8
votes
1answer
2k views

Making API calls with celery

I'm designing a system for a client where the requirements are: they upload a JSON file (one object/line) make a call to an API with the JSON object as the payload record the state (success/failure) ...