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
-4
votes
0answers
23 views

How to assign random words or phrases to a list of set terms

I am writing an algorithm which uses Machine Learning to categorize posts right after they are created in my database. I have a set of 370 terms that another algorithm uses to display it to the right ...
-3
votes
1answer
47 views

Dynamically process data out of CSV file

I have a .csv file that stores some information about different people and looks like this: Username; Identifier; First name; Last name booker12; 9012; Rachel; Booker grey07; 2070; Laura; Grey ...
0
votes
1answer
35 views

How to efficiently communicate with Raspberry Pi using Django/Python

I have a raspberry pi that is sending an https request to my Django application every 2 seconds. The request is essentially asking the application 'Has a user requested data from me?' My Django ...
1
vote
1answer
57 views

Python import order, mixing from … import … and import … (and import … as …)

This is the mess of imports currently at the top of my file: import argparse from copy import deepcopy from functools import cmp_to_key, partial from itertools import chain import math from ...
-4
votes
0answers
52 views

How does AI voice work? [closed]

Google AI or Siri or Alexa they have their own voices and I want to know how the voices was given. I want to make a Pdf reader but with custom voice and language so how can I develop one. I have tried ...
-3
votes
0answers
38 views

Fairly assigning employees to tasks for each workday- what approach to choose?

I'm trying to write GUI application which will be fairly assigning employees to tasks for each workday. The most hard part of this is to create some algorithm which allow to solve this kind of problem....
0
votes
1answer
41 views

Using rest services or python modules directly?

Imagine you're in a Python setup, with all of the projects you're working on. Now, as a base line, you have a Python module that is the backbone (backbone.py) to everything when it comes to getting ...
-4
votes
0answers
34 views

Best Practice for lifting classes from 2d to 2d in python

I am currently writing a simulation in python which is running in 2D. I want to extend it now to 3D and therefore I have to change the classes like the simulation grid. My question is what is ...
-2
votes
0answers
20 views

How can I run a Python update-able job scheduler asynchronously?

I'd like to run a job scheduler concurrently with/to the Python main thread. The jobs have to be executed with a relative delay in the sub-second region. In addition I want to update jobs (the ...
0
votes
0answers
65 views

value-based function dispatch

Problem to solve I have a method parse_doc that should dynamically determine a parsing function to parse document_id based on the value of the document_id string: # list of files that may have ...
0
votes
2answers
67 views

Relation many-to-one between objects in Python

I'm doing scientific computations using Python. So far I have a module core and a class Simulation inside. There are many instances of Simulation at the runtime but all of them must share the same &...
-1
votes
0answers
57 views

Correct algorithm to sort generated C/C++ items

I'm in the process of designing a code-generation system that will take from simple JSON files the description of structures, enumerations and functions, and output code from these descriptions to C ...
1
vote
2answers
94 views

Unit testing a function that composes filters

Imagine there is a number of filter functions that all perform filtering of items in a list based on different criteria. Say there are 5 such filter functions. All unit tested Now imagine there is ...
0
votes
1answer
59 views

How to determine ideal chunk size for file writing?

I have a class that is responsible for writing formatted binary objects to a file on a network drive with a 100Mbps bandwidth. Each time an object is created (via lets call it w.addObj()) it formats ...
-2
votes
0answers
28 views

What is a good pattern for passing a list of constant strings to front-end via GraphQL

This is using Python and the Graphene library. I want to provide a list of constants to my front-end via GraphQL. I went down the route of using inspection, but it will only output the keys of the ...
-2
votes
0answers
18 views

In Spark can the data be processed by querying database before transforming to RDD

I am very new to Spark. My System The data from kafka is consumed in Spark This data next needs to be processed by querying database to get the relevant formula for manipulation The thus processed ...
0
votes
1answer
65 views

Versioning of data handling pipeline elements

I have developed a custom-made Python package, which provides 2 classes to play with: Stage and Step. They operate based on a Chain of Responsibility design pattern, and behave in a way where: Both ...
-3
votes
0answers
46 views

how does the interpreter in cpython work?

I read that "all the objects in cpython are represented as pyobjects(which is a structure) in c". why are we even bringing c programming into context? This is my understanding so far about ...
-3
votes
3answers
88 views

is python(cpython) code represented as c code by the interpreter?

what i know is , in cpython when we run a code then its first compiled into byte code and the cpython interpreter( which is written in c interprets it) interprets the byte code and converts it into ...
1
vote
1answer
96 views

Should I stub hidden dependencies in Python unit tests

Python is very specific language which gives developer huge flexibility. So if I have class like this: class Car: def __init__(self, engine: Engine): self._engine = engine # dependency ...
-3
votes
0answers
48 views

How to maintain data redundancy between python machines?

I have a data science application that loads a trained model into memory. The application is distributed on two machines that are called using load balancing. The problem is that the model is updated ...
-4
votes
1answer
52 views

Python: Help with replacing list comprehension with generators [closed]

I have written the following code which takes a coord_list of points in a 2D coordinate system, a center and a radius and returns a list of all points from the list having distance at most radius from ...
0
votes
1answer
41 views

Approach for Querying Relational Data

Setup Consider the following models (pseudo-code) Place: type: const = "Place" id: str name: str lat: float lon: float # other fields Event: type: const = "Event" ...
-2
votes
0answers
27 views

How to handle big data analytics on web?

I'm working on a project based on django (python) and mongodb as database that shows some analytics(figures produced from calculated data from database) based on some csv data. Currently my local ...
-3
votes
1answer
90 views

How Uber processes orders?

Lets say you created an order. Since Uber is a very dynamic system, one should constantly check if there are available drivers for you. If orders are saved as a some collection (e.g. in MySQL table ...
2
votes
1answer
69 views

Pattern for creating an instance of a class from a UI form

The following is a contrived example of a potential code smell that I've repeatedly encountered when implementing a GUI with which instances of a class created by letting the user fill out a form. The ...
1
vote
1answer
104 views

How deep should I mock dependencies in unit tests

Consider the following function: def get_api_status(api_client): response = api_client.get('/status/') return response.content and the test for it: def test_get_api_status(): ...
1
vote
1answer
62 views

Python: Class vs NamedTuple vs Hybrid vs DataClass

So all four of these approaches to structure data on their surface work more or less the same to keep data well structured. Are there any reasons, be they hidden performance issues/enhancements, ...
-1
votes
1answer
87 views

Refactoring: Pythonic way of reducing the subclasses?

background: so, I am working on an NLP problem. where I need to extract different types of features based on different types of context from text documents. and I currently have a setup where there is ...
-1
votes
1answer
71 views

How should I document a higher-order Python function?

I'm interested in designing a high level function in Python, (I.E. a function that takes other functions as arguments) but I don't know of any good conventions for documenting such a function. For ...
1
vote
1answer
143 views

When should an argument be set to None in Python?

The focus of my question is on design. If I have an argument that can be None and it is passed between several functions until finally being used, which function should treat it as a default argument? ...
1
vote
2answers
119 views

Choosing between DI (without container) and Composition

I'm working on a classes that are designed to read a defined file format; said format is comprised of 2 separate files (FileA and FileB). For ease of use, the format is referred to as the FileA format,...
2
votes
0answers
32 views

Update class member gradually [duplicate]

Consider the following: import typing class MyClass(object): def __init__(self): self.my_member: typing.Optional[dict] = None def update_member(self): self.my_member = {} ...
-1
votes
1answer
45 views

Efficiently keep different data structures synchronised - tree, list of objects

Problem description I have a pet project to translate TEI XML to standoff JSON and back: https://github.com/standoff-nlp/standoffconverter and I am currently thinking about a rewrite/restructuring. ...
2
votes
2answers
97 views

How can I efficiently make changes to a large module without having to re-run every time?

When making changes to larger modules in Python, this is my current (inefficient) process: Make needed change to code Run program to test (using pdb - python3 -m pdb path/to/script.py Program will ...
3
votes
4answers
197 views

When to have ID of instance as an instance field vs. decoupled?

Let's say I have a class called ValueSpec with these immutable instance fields: min_value: int max_value: int description: string Each instance of ValueSpec is uniquely named. This unique name is ...
0
votes
4answers
166 views

Loose coupling in Python

While I know this is the tight coupling example: class User: def __init__(self): pass def get_status(self): api_client = APIClient() status = api_client....
5
votes
6answers
391 views

How to modify object properties?

I've recently read a great article about unit testing. There was an example of a bad method which is not well designed. It looks like this public static string GetTimeOfDay() { DateTime time = ...
3
votes
2answers
215 views

What is the rationale for making certain methods for data types static?

In C#, for instance, there are static methods for telling if a string is null or empty, finding an element in an array, clearing an array, etc. However there's an instance method for replacing ...
-4
votes
1answer
63 views

Better way to process huge files

I have a huge csv file and I have to process that file and do some data manipulation. Right now I'm reading/loading the file in buffer and then doing the data processing work. I find this approach ...
0
votes
1answer
91 views

What are the benefits of not checking function arguments in python?

I'm trying to understand what are the benefits of the fact that python defaults to not checking function arguments. For example: from some_module import my_function my_function(some_argument) # ...
1
vote
2answers
81 views

Trying to figure out the optimal selection based on a set of rules

Background: We have software that displays different products to the user Problem: With a given set of rules, determine which is the primary product we should show the user. These are images. We are ...
0
votes
0answers
82 views

Python circular dependency

I have two classes AST and ASTNode for working with some tree-like data. Both these classes have networkx graph as a field and a node id (integer). For AST this id refers to the root of a tree. These ...
1
vote
2answers
45 views

add function to input of builtin python logger

For simplicity, assume my application logs only dictionaries. I want to add a step to Python logging for my application to prevent logging any dictionary with the key password, i.e., def clean_log(...
2
votes
1answer
85 views

Converter implementation in Python: class versus module?

I've written a little library that uses the builtin ast library to convert between functions, docstrings, argparse .add_argument, classes, and [soon] more. Stubs look something like this, with ir ...
15
votes
1answer
4k views

Is it possible/advisable to combine unit testing and integration testing?

I've built a Python script that consists of about 20 functions that extract data from MySQL via .sql files (I'm currently trying to learn SQLAlchemy ORM), do something to it and then put it back in ...
1
vote
1answer
97 views

When modules written in different languages interact, is exchanged data always serialized?

I have module written in Python and I would like to write function in e.g. Go but problem is that data needed for computations is often more than 100MB. My question is: is data always serialized and ...
-4
votes
1answer
107 views

What things should you consider when porting software from python to c++?

Suppose you have written a prototype for an application in python, now you want to rewrite it in c++ for speed reasons and to make a real software out of it. What are things to consider before ...
-2
votes
1answer
61 views

How the basic structure of a simple messaging app works?

How the messaging apps works? What is the Basic algorithm of it? I tried the following method to make a messaging app. I enters message Message converts to a text file Text text file uploads to the ...
-3
votes
2answers
157 views

Should I use Flask w/ Javascript OR a Javascript UI that calls a Flask / Connexion API?

I recently wrote a data management tool in Python & SQLAlchemy. Now, I need to put a web UI on it. While I want to start small, there is some need for interactivity, like drag and drop in tables, ...

1
2 3 4 5
35