Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [python-3.x]

Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
42 views

Are there different ways in Python to decorate class methods that dynamically assign themselves to a dict within the class?

Here's what I'd like to do in the form of working code, since it's difficult for me to explain otherwise: from typing import Callable, Generic, TypeVar from typing_extensions import Self # The type ...
user avatar
2 votes
1 answer
169 views

What is the best way to compartmentalize complex logic problems?

I am working on a problem with lots of if-then-else calculations. I am trying to compartmentalize the logic to make it more maintainable and less error prone. But, as I try options, I don't see what ...
user avatar
0 votes
3 answers
121 views

Python best practice when logging optional arguments

I have a method that accepts one or more optional arguments and I'd like to log them, following the best practice of lazy interpolation of log values: def frobnicate(a: str, b: int, c: typing.Optional[...
user avatar
  • 109
4 votes
2 answers
159 views

Should similar standalone functions go in a class?

I'm working to create a library in python that myself and a few colleagues will use. I'm struggling to conceptually understand how to best organize some code that feels like it doesn't cleanly fit ...
user avatar
  • 79
-4 votes
1 answer
70 views

How to use DRY methods with OS commands with Python and classes

My goal is to learn more about OOP patterns and use DRY principles. I am trying this for wrapping an os command that interacts with a database using classes: This works fine: import subprocess class ...
user avatar
9 votes
6 answers
4k views

Is it reasonable to use dictionaries instead of arguments?

In python I often see functions with a lot of arguments. For example: def translate(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p): // some code return(x, y, z) I like this pattern in some ...
user avatar
0 votes
0 answers
168 views

How to structure a global config that needs to be available at import time? (Python)

I've got a Python application (imagine a Flask app, but this question is not specific to Flask). I have an App object and a Config class that I instantiate with values from a file. Normally in the ...
user avatar
  • 121
1 vote
1 answer
320 views

Type-hinting and accessing values that are not initialized in __init__ (Python)

Suppose I have an instance attribute that I don't initialize in __init__, but in normal use it should be initialized before any other methods use the value. I want to structure everything so that it ...
user avatar
  • 121
0 votes
0 answers
26 views

Sync image files from network with mariadb-Database

i have as a mechanical engineering student in my practice semester to create a database that includes about 100k+ paths to images in our network. Every, lets say week, i have to synchronize all ...
user avatar
24 votes
8 answers
7k views

Is using lambdas to express intent not pythonic?

PEP 8 states the following about using anonymous functions (lambdas) Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier: # Correct: ...
user avatar
0 votes
0 answers
24 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 ...
user avatar
0 votes
1 answer
103 views

designing high throughout system for storing hundred thousands incoming records per second in SQL server database

In our company we have a requirement where we would like to store hundred thousands incoming records per seconds. we currently a pub-sub model for processing many records(100/sec) from many system(~...
user avatar
1 vote
1 answer
102 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 ...
user avatar
  • 141
0 votes
0 answers
65 views

Proper way to implement AWS Cognito

I am trying to implement AWS Cognito with Chalice. I understand that ID Token is to identify the user (authenticate), Access Token is to authorize to run operations on resources, and Refresh token is ...
user avatar
0 votes
0 answers
18 views

Python Banking Transfers Systems Backend

I'm wondering how banks that use cards with chips for their transfers, actually recieve the information (like if the banks backend was written in python, how would the data be recieved, in a json ...
user avatar
0 votes
3 answers
811 views

"Hard coded" vs. configuration files for values in libraries? (code organization question)

I'm trying to get a good understanding as to whether there is a best practice or standard regarding keeping values within your code libraries or referencing them from another config file. I don't ...
user avatar
  • 3
-1 votes
1 answer
74 views

In a language interpreted line by line - is optimizing similar lines of code within a module into functions better in terms of efficiency? [duplicate]

While writing python code (I write python-selenium for GUI automation), I am facing situations wheer I have to deal with 5 widgets that do the same thing, just there xpath is differs by one term. # ...
user avatar
-1 votes
1 answer
87 views

How to design "define-by-run" API?

I am amazed by the way APIs of some machine learning packages are designed, namely Chainer's and Pytorch's "define-by-run" API. Even Optuna, a hyper parameter tuning library has "define-...
user avatar
2 votes
2 answers
946 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'...
user avatar
  • 409
-1 votes
1 answer
358 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 [...
user avatar
  • 191
1 vote
2 answers
1k views

Is a python `abstract property` that returns an abstract class an example of the Factory Pattern?

I need to document my design, in particular, the design patterns used, and would like to use the standard terminology. From Refactoring Guru, "Factory Method defines a method, which should be ...
user avatar
  • 137
2 votes
2 answers
266 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 ...
user avatar
-1 votes
1 answer
1k views

Python dynamically import modules

I am trying to find the best practice for importing modules dynamically. I have multiple files in a specific folder called providers which contain a class Updater and all of them have the same objects....
user avatar
  • 31
-4 votes
1 answer
54 views

Reading txt file till certain point and then create new txt file out of existing file

I have a txt file from where I want to create new files based on the data which is up to '$'character. My input file looks like: string1 string2 string3 $string4 string5 $string6 string7 ... (and so ...
user avatar
  • 11
-3 votes
1 answer
131 views

Test to check that executing a function does not raise an exception

I have the following function: def create_dic(): key_list = ['a','b'] val_list = [1, 2] dic = {} for i in range(2): dic[key_list[i]] = val_list[i] return dic I ...
user avatar
  • 113
1 vote
1 answer
107 views

How to deploy python microservices app updates?

I'm working on python microservices based app and I'm wondering how to ship updates. Let's start by a summary of what I have: Code base on git (several repos) The app is running on several remote ...
user avatar
  • 13
0 votes
1 answer
85 views

Class Design question concerning adding a new "DRAFT" state to an object

We have some entities in our code: -"View" and View has some attributes and also contains one or many "SubViews" -And each "SubView" has some attributes and contains one or more "Tweet" entities. ...
user avatar
-4 votes
1 answer
77 views

Best practices when interfacing Python and C code

I have a piece of code that I developed in an academic context for which I would like to build a nice frontend. My approach to coding has been very academic to this point (read: I made stuff up as I ...
user avatar
  • 115
1 vote
0 answers
121 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":...
user avatar
-2 votes
1 answer
78 views

Finding the domain(s) of variables in a Linear Program using the constraints? (Constraint programming/Linear programming)

Forgive my jargon , as I'm not very familiar with Constraint Satisfaction Problem(s) or Linear Programming procedures (For eg: Presolve) I have very trivial constraint set from variables of ...
user avatar
-1 votes
1 answer
286 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 ...
user avatar
-4 votes
1 answer
155 views

Python Code Design - How should I have used OOP?

Edit: My main question is how would you structure and design code to accomplish the project I describe below. Please try and think of this as a technical interview question and you have to describe ...
user avatar
-2 votes
1 answer
162 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: ...
user avatar
2 votes
1 answer
139 views

Event Handling in Pygame

I am working on setting up a game in pygame and I've noticed that there isn't really a lot available for event handling. Basically, pygame has a queue of events that you can pull and iterate through ...
user avatar
-1 votes
3 answers
498 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 ...
user avatar
0 votes
2 answers
663 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. ...
user avatar
0 votes
1 answer
135 views

How to expose multiprocessing python application to support invocation from command line and web

I have a python forecasting application that, for a given Entity, executes a fbprophet model multiple times varying the hyperparameters for each execution while tracking the best fit across the runs. ...
user avatar
2 votes
2 answers
1k 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 ...
user avatar
0 votes
0 answers
109 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 ...
user avatar
  • 67
-5 votes
1 answer
310 views

Upload fingerprint from android/ios to cloud

I am working on a project to use fingerprint to authenticate the user. I don't want the authentication to be device specific. Hence want to upload the user fingerprint to cloud. I do understand that ...
user avatar
0 votes
0 answers
3k 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 ...
user avatar
-3 votes
1 answer
315 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 =...
user avatar
  • 97
1 vote
1 answer
73 views

Api limit access to subscribers only

I have a vanilla php api(on a vds) and I want to make data coming from that api available to a few clients that are using a python app that's also written by me. That python app is running on my ...
user avatar
  • 19
2 votes
2 answers
106 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 ...
user avatar
1 vote
1 answer
68 views

How do the (presumably sync) loop runners launch the async event loop?

Where is the implementation interface in Python documented that allows the async loop runners (from trio, asyncio, curio) to start the whole shebang? We know that sync functions cannot call async ...
user avatar
0 votes
3 answers
109 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 ...
user avatar
  • 1,637
4 votes
1 answer
219 views

Is using getters to exchange information between objects acceptable?

Suppose I have the following Character, Potion, and PotionType classes: class Player: def __init__(self, name: str, health: int, mana: int): self._name = name self._attributes: ...
user avatar
-3 votes
1 answer
371 views

what is a difference between resource and source in programming [closed]

I had a question for separating my python project files. What is a difference between "resource" and "source" in programming? When I should use "resource" separation and When I must use "source"?
user avatar
2 votes
3 answers
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(...
user avatar
  • 145
2 votes
1 answer
74 views

Why doesn't Python3 optimise variables assignments

I just read this SE question about parameter optimisation. I wondered if Python3 bytecode compilation does the same optimisation and this appeared not to be the case: >>> def f(a): return 2*...
user avatar
  • 129