Skip to main content

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
5 votes
2 answers
739 views

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 ...
noamtm's user avatar
  • 235
-3 votes
2 answers
5k views

I mention python's argparse as an example but this would apply to any CLI argument parser library for any language. Just generally speaking, at a high level, if there are a lot of optional arguments ...
notacorn's user avatar
  • 109
1 vote
3 answers
626 views

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 ...
NealWalters's user avatar
1 vote
0 answers
65 views

As a toy problem for learning Django, I am trying to create a simple web app that tracks encounters and initiative for one of my D&D campaigns. I have a database with models for combatants: class ...
Brandon Smith's user avatar
2 votes
3 answers
457 views

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 ...
nonohat's user avatar
  • 53
0 votes
2 answers
360 views

I'm using argparse.ArgumentParser extensively; however, it comes with a lot of boilerplate to set up, and this is especially noticeable when you've got more than a few common arguments that probably ...
g_elef's user avatar
  • 19
0 votes
1 answer
232 views

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 ...
serge's user avatar
  • 9
1 vote
0 answers
95 views

I have the following piece of code. Line 1 is a container (for simplicity, one can think of it as a list of elements e1, e2, ..., en). Now there is a function function_fun which takes as input an ...
A J's user avatar
  • 19
2 votes
2 answers
170 views

Consider the following python3 code: from abc import ABC, abstractmethod class Food(ABC): _food_factory_map = {} _recipes = {} @classmethod def getFood(cls, foodName): return ...
raghavj's user avatar
  • 29
1 vote
2 answers
1k views

I'm working on a python library for a REST API.I'm using python data classes to represent the structure of the returned JSON The v2 of this API returns a slightly different object when compared to v1. ...
rsn's user avatar
  • 127
1 vote
0 answers
1k views

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 ...
rsn's user avatar
  • 127
21 votes
6 answers
7k views

In Python 3, I subclassed int to forbid the creation of negative integers: class PositiveInteger(int): def __new__(cls, value): if value <= 0: raise ValueError("value ...
swoutch's user avatar
  • 321
-2 votes
1 answer
91 views

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 ...
user247243's user avatar
2 votes
1 answer
4k views

I have a class that I use to define different types of plots I am performing class MyPlots(Enum): STANDARDSCALE = "standard" LOGSCALE = "log" there are default values ...
La Cartuccia's user avatar
5 votes
1 answer
365 views

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. ...
Jinx's user avatar
  • 159
-1 votes
1 answer
2k views

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 ...
lapraswastaken's user avatar
2 votes
2 answers
334 views

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 ...
eSurfsnake's user avatar
0 votes
3 answers
3k views

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[...
Luke404's user avatar
  • 109
4 votes
2 answers
2k views

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
-4 votes
1 answer
93 views

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 ...
james6125's user avatar
13 votes
6 answers
12k views

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 ...
P. Hopkinson's user avatar
2 votes
1 answer
4k views

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 ...
nullUser's user avatar
  • 139
0 votes
0 answers
55 views

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 ...
Prodigy's user avatar
24 votes
8 answers
7k views

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: ...
N3buchadnezzar's user avatar
0 votes
1 answer
129 views

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(~...
vector8188's user avatar
1 vote
1 answer
177 views

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 ...
Serenity's user avatar
  • 141
1 vote
3 answers
6k views

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 ...
Kyle's user avatar
  • 13
-1 votes
1 answer
94 views

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. # ...
Ulysses's user avatar
  • 101
-1 votes
1 answer
367 views

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-...
Manishankar Singh's user avatar
1 vote
2 answers
5k views

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'...
sunyata's user avatar
  • 477
-1 votes
1 answer
2k views

(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 [...
SimpleOne's user avatar
  • 199
1 vote
2 answers
2k views

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 ...
Blue7's user avatar
  • 137
3 votes
2 answers
1k views

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
2k views

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....
bkbilly's user avatar
  • 131
-4 votes
1 answer
1k views

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 ...
IvanM's user avatar
  • 11
-3 votes
1 answer
3k views

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 ...
Mencia's user avatar
  • 113
1 vote
1 answer
188 views

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 ...
AFZ84's user avatar
  • 13
0 votes
1 answer
205 views

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. ...
user642770's user avatar
-4 votes
1 answer
150 views

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 ...
KBriggs's user avatar
  • 115
1 vote
0 answers
207 views

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":...
inquilabee's user avatar
-2 votes
1 answer
142 views

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 ...
Prasanna 's user avatar
-1 votes
1 answer
418 views

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 ...
Khubaib Khawar's user avatar
-1 votes
1 answer
247 views

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: ...
In Hoc Signo's user avatar
2 votes
1 answer
367 views

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 ...
severestrength's user avatar
-1 votes
3 answers
612 views

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 ...
Edoardo Busetti's user avatar
4 votes
2 answers
7k views

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. ...
majorpain1588's user avatar
0 votes
1 answer
174 views

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. ...
Jay Walker's user avatar
2 votes
2 answers
2k views

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 ...
Techoplite's user avatar
0 votes
0 answers
127 views

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 ...
PanNik's user avatar
  • 67
-5 votes
1 answer
431 views

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 ...
user420528's user avatar