Skip to main content

All Questions

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

Is it better practice to set default values for optional argparse arguments?

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
21 votes
6 answers
6k views

Does subclassing int to forbid negative integers break Liskov Substitution Principle?

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

How to add some data to an Enum in Python

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
-1 votes
1 answer
2k 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 ...
lapraswastaken's user avatar
0 votes
3 answers
2k 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[...
Luke404's user avatar
  • 109
13 votes
6 answers
11k 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 ...
P. Hopkinson's user avatar
2 votes
1 answer
3k 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 ...
nullUser's user avatar
  • 139
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: ...
N3buchadnezzar's user avatar
1 vote
1 answer
171 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 ...
Serenity's user avatar
  • 141
2 votes
2 answers
5k 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'...
sunyata's user avatar
  • 479
-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 [...
SimpleOne's user avatar
  • 199
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 ...
user avatar
1 vote
0 answers
203 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":...
inquilabee's user avatar
-1 votes
1 answer
397 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 ...
Khubaib Khawar's user avatar

15 30 50 per page
1
2 3 4 5
7