All Questions
Tagged with python python-3.x
90
questions
0
votes
0answers
14 views
Configuration file handling in ORM libraries
I maintain several ORM libraries written in Python 3 using peewee.
In order to use the ORM models, i.e. operate on the database through them, the database object needs to be configured with the ...
1
vote
1answer
81 views
legacy refactor and churn
I am trying to work on finding the following metrics
New Work - totally new code which does not replace other code.
Churn - code that is rewritten or deleted after being written
Help Others - where ...
1
vote
2answers
227 views
Alternative to using regex in Python
Background
I do programming with Python and now and then i run into a situation where i have to use regex
Typically i try to learn a bit about it and look at examples of doing things similar to what i'...
-1
votes
1answer
153 views
Python generating payload and parsing payload
(Using python) I am looking to generate a bytes (or can be string that I convert to bytes) that is a message to send over TCP. The format is [Header][Length][Payload].
Within [Header] is a [...
2
votes
2answers
174 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 ...
1
vote
0answers
95 views
Combine/Sync Amazon S3 and MongoDB Atlas with Elastic Search
I have many continuously growing (through scrapping) collections in MongoDB Atlas. The documents in each collection follows the following schema:
{
"source_url": "<some url on the web>",
"html":...
-1
votes
1answer
212 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 ...
-2
votes
1answer
144 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:
...
-1
votes
3answers
442 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 ...
1
vote
2answers
119 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. ...
2
votes
2answers
768 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 ...
0
votes
0answers
104 views
How to design realtime deeplearning based application for robotics using python?
I have created a machine learning software that detects objects(duh!), processes the objects based on some computer vision parameters and then triggers some hardware that puts the object in the ...
0
votes
0answers
2k views
What is the fastest way to parse variable record binary files in Python?
The Python Binary File Parsing Deep Dive
Intro
I'm an electrical engineer by trade, however my job has a lot of software engineering overlap. Recently something I've been working on is a Python ...
-3
votes
1answer
309 views
Why do people keep reusing superclass names in their subclasses?
In my project, I found one of the project's classes reusing the same name as an official one.
For example:
from django.db import models
class Model(models.Model):
class Meta:
abstract =...
2
votes
2answers
102 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
3answers
102 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 ...
2
votes
3answers
1k 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(...
-1
votes
1answer
193 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
votes
1answer
87 views
Can i be two places at once in python cycle
I'm doing this in python, in case that changes anything.
I'm trying to make a lamp/bit go 1-0-1-0 until the user says "okay"
the "okay" should indicate that the user has found the lamp/Bit IRL.
Now ...
3
votes
0answers
106 views
Python3: How to change the design of a class hierarchy to improve access to objects there buried?
I asked this question already at stackoverflow together with a serialization related part and at codereview for the design part only. Since the design related part receives no answers or comments on ...
2
votes
1answer
35 views
An approach to send the contents of a file on the server to the client in real-time
I have a relatively simple front in good ol' JQuery, that makes a POST Request to a Flask Python web server, that runs a Python script using the subprocess module. Here's the whole route for ...
1
vote
1answer
311 views
Does the fact that random.sample(seq, 1)[0] === random.choice(seq) mean that both functions should have the same precondition on seq?
I've read https://bugs.python.org/issue33098, which is about the following behavior of Python 3
a = {'1': 42, '2': 84} # keys are str on purpose, c.f. the issue
import random
random.choice(a.keys())...
5
votes
1answer
2k views
Convince people not to use an “end-of-life” Python 3.X version
Context
At my company, we have a major Python package which is written in Python 2. We are now planning to migrate it to Python 3 (we don't care about keeping it Python 2 compatible).
I am a junior ...
2
votes
1answer
95 views
Is it considered bad form to call `next` on the input sequence of a list comprehension?
I want to extract lines from a stream that are preceded by the character L. The list comprehension below does the job, but calls next on the stream inside the comprehension in a way I've never seen ...
171
votes
23answers
25k views
Programming cleanly when writing scientific code
I don't really write large projects. I'm not maintaining a huge database or dealing with millions of lines of code.
My code is primarily "scripting" type stuff - things to test mathematical ...
2
votes
3answers
241 views
Should I test the debug branch of my code in a unit test?
Lets say I have a function that gets a list of what files to send that are later send over a socket to some other pc. Now usually I keep track of what files have been sent and don't send these files ...
1
vote
1answer
923 views
How are list elements accessed in python internally?
Like if I want to access an array element in C it's implemented like this:
For example: If a = {0, 1, 2, 3} is an array if I want to access index number 2 I will write a[2] and the formula that is ...
0
votes
2answers
150 views
Difference between interaction log and “debug” or “application” log
Let's say I need two logs coming out of my application. One is for debugging issues and making sure the application runs correctly and the other is used for user statistics and general analysis of the ...
4
votes
1answer
216 views
Split ORM module without creating cyclic imports or side-effects
Preface
I have an ORM library for a relational real estate database. The used framework is peewee. The library contains ~60 models, each representing a distinct table. The models represent a (pre-...
1
vote
2answers
440 views
Enforce strict naming of multiple arguments
I have some questionnaire data in CSV files for different projects. I created a function that takes a specific subset of columns and calculates aggregated values. The problem is that across these ...
2
votes
1answer
340 views
Speech to text - action - text to speech: architecture/logic. Is there a better way to build my robo-player?
I have decided to start a personal project using Python since I have used it for several years now and I would like to know if the approach that I have considered is good or not.
Description
It's ...
3
votes
0answers
89 views
Software design strategy for a machine learning tool that outputs a subset of the text input (Information Extraction)?
Let's say I have thousands of pdfs that are each about 30k words written in conversational English. In each of the pdfs there is a name / names of a person/people who snowboard. There are also many ...
1
vote
2answers
215 views
Actions that can have individual cooldowns or a “group” cooldown
I'm creating a game (well, a plugin) where each player has a list of skills, each of which has an unique type object, each of which has a list of actions that need to be ran when a player executes his ...
0
votes
1answer
607 views
Should I produce output with yield or stream.write in Python 3?
I am working on a Python 3 program that will among other things write data to text files in a number of formats. I have one function per format, generating the data to be written. I see two possible ...
3
votes
5answers
11k views
Why are Python sets and dictionaries not ordered by default?
I understand the difference between ordered and unordered sets, and I understand why for many purposes, we don't need ordered sets. But all set operations are still possible on ordered sets, and sets ...
0
votes
2answers
395 views
Dynamically choose whether to use __slots__ in a class
I've got a generic container class:
from typing import Container, Generic, TypeVar, NamedTuple
import sys
fixed_typing = (sys.version_info >= (3, 6, 2) or
(3, 5, 3) <= sys....
2
votes
1answer
2k views
What is the difference between the solution that uses defaultdict and the one that uses setdefault?
In Think Python the author introduces defaultdict. The following is an excerpt from the book regarding defaultdict:
If you are making a dictionary of lists, you can often write simpler
code using ...
-1
votes
1answer
320 views
The pythonic way: replacing interfaces with ducktyping vs inheritence
tldr: I have consumer-like classes that require a number of pieces of information to do their job. It's an "all or nothing" kind of thing: the "producers" providing them with data need to provide all ...
2
votes
2answers
909 views
Is “A programmer-defined type.” a right definition of “class” in Python?
In Think Python 2e "class" is defined as "A programmer-defined type. A class definition creates a new class object."
But isn't a built-in type considered a class too?
Using Python 3.4.0, the ...
2
votes
0answers
1k views
How to improve the detection of Probabilistic Hough Line Transform?
I'm trying to detect a clock hand in a video of an analogue display and extract the value it points to. I'm using Python with OpenCV for this.
What I essentially do is:
I'm using a Gaussian Blur to ...
84
votes
7answers
22k views
How bad of an idea is it to use Python files as configuration files?
I've always used JSON files for configuration of my applications. I started using them from when I coded a lot of Java, and now I'm working mainly on server-side and data science Python development ...
3
votes
1answer
2k views
Pattern for subclass overload with different arguments
I'm in the process of writing an bidirectional, asynchronous socket server and server handler. The base handler class I'm working off of is as follows:
class BaseAsyncSocketHandler:
async def ...
2
votes
1answer
822 views
Custom language with mixed markup and Python, parsing in Python
I need a system for creating Python subclasses in a simple manner, and I was thinking of using a (custom) config language similar to json, xml, etc.
Here's the initial structure I thought of (one ...
-2
votes
1answer
80 views
Python Syntax Format
Since I am new to programming, I just want to understand the format the built-in functions is represented in the documentations. This is the one from python
bytearray ([source[, encoding[,errors]]])...
1
vote
2answers
1k views
Best way to import a large module to use in different modules
I have a python module dataProcessor.py which initialises a large amount of data into memory (approximately 3GB) I want to use this module in different processes which are running simultaneously.
...
1
vote
0answers
80 views
Should I pull the language data files of a project from a GitHub repository?
I am currently in a dilemma. I am thinking about downloading a JSON file from a GitHub repo to replace local files. The local files are stored in a folder named lang, which is stored in the project ...
3
votes
1answer
128 views
Documenting variables in a Python module
I am writing a Python module that uses Numpy. I am trying to follow the Numpy docstring format. In many of my functions, the same parameters show up. It seems repetitive to explain what they are in ...
7
votes
1answer
429 views
API design: stream objects vs. functions vs. messages
I'm designing API for a python library that accepts asynchronous input and produces the asynchronous output: various signals come in, and various signals are generated in response (there's no one-to-...
5
votes
2answers
8k views
How many types of polymorphism are there in the Python language?
I just read an article by Luca Cardelli and he explained types of polymorphism which are:
The article is named On Understanding Types, Data Abstraction, and Polymorphism.
Types of Polymorphism
...
15
votes
2answers
10k views
How should I name functions that return values in Python?
I'm confused about choosing names for my functions in Python. Sometimes Python built-in functions are imperative such as: print function and string method find. Sometimes they aren't such as: len its ...