Questions tagged [python-3.x]
Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008.
156 questions
5
votes
2
answers
736
views
Why did Python designers decide not to declare vars? [closed]
In Python when you want a local variable, you just assign to it x = 10.
In most modern languages you declare local vars (regardless of type):
JavaScript: let/const/var
Swift: let/var
Kotlin: val/var
...
1
vote
3
answers
616
views
Python logging in shared functions called by multiple main programs
I have reviewed this, but it doesn't seem to address what I'm asking here.
https://stackoverflow.com/questions/15727420/using-logging-in-multiple-modules
I want to have multiple programs call the same ...
2
votes
3
answers
457
views
Does it make sense for an API with 1 daily job to do to be asynchronous?
This is a conceptual question about whether my specific use-case warrants the use of an asynchronous API.
Language: Python 3.11
Framework: FastAPI (ASGI)
I believe I am confused about what an ...
0
votes
1
answer
231
views
Match making algorithm respecting players' choices
I am currently developing an application in Python that has a match making functionality to form sports teams of 4 and group them by skill. The following has been implemented and works.
E.g.
Form ...
2
votes
2
answers
170
views
OOP Best practices: Is there any reason to separate out Factory functionality from an abstract base class?
Consider the following python3 code:
from abc import ABC, abstractmethod
class Food(ABC):
_food_factory_map = {}
_recipes = {}
@classmethod
def getFood(cls, foodName):
return ...
1
vote
0
answers
1k
views
Python - Where do I store data classes which are common across different files?
I'm working on a python wrapper for a REST API. I'm using python data classes to store the shape of the JSON response of each endpoint so developers have features like autocomplete and objects they ...
-2
votes
1
answer
91
views
python language construct or facility to tag entering and exiting a while loop
Here's what I want to achieve:
while complex_compound_condition_statement:
foobar() # ... do some stuff
I would like the log output of the above to be:
<timestamp> INFO: started doing stuff ...
5
votes
1
answer
365
views
Does my View Model violate the Single Responsibility Principle? Or am I just used to toy examples from tutorials?
I am a very beginner writing one of my first webapps. I'm using FastAPI and I'm stuck on the logic of creating an endpoint that has to do a lot of things before it returns something back to the user. ...
2
votes
2
answers
333
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 ...
4
votes
2
answers
2k
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 ...
13
votes
6
answers
12k
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 ...
0
votes
0
answers
55
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 ...
0
votes
1
answer
127
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(~...
1
vote
3
answers
6k
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 ...
-1
votes
1
answer
365
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-...
-1
votes
1
answer
2k
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 [...
3
votes
2
answers
1k
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
1
answer
1k
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 ...
1
vote
1
answer
187
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 ...
-4
votes
1
answer
150
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 ...
-2
votes
1
answer
142
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 ...
-1
votes
1
answer
246
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
3
answers
612
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 ...
0
votes
1
answer
173
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. ...
0
votes
0
answers
127
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 ...