2,204,267 questions
Score of 1
0 answers
25 views
Compare lists in one column to the first n elements of another column in Python Polars lazyframes, where n is dynamically determined from index
I'm trying to compare words present within sentences in one column, to the first n words in a wordlist (in another column), and return the words in the sentences that don't exist in that subset of the ...
Score of -2
1 answer
52 views
Changing WSGI app makes SQLite file unable to be found
I am trying to move from a prepackaged Flask/uWSGI to a custom Docker with Gunicorn. My Dockerfile is changed into:
FROM python:3.13-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
...
Score of 0
1 answer
110 views
Should module-level constants in constants.py be annotated with typing.Final
According to the docs, typing.Final is:
Special typing construct to indicate final names to type checkers.
Final names cannot be reassigned in any scope. Final names declared in class scopes cannot ...
Score of -2
0 answers
109 views
Making a bar chart with varying values along the y-axis
I'm trying to make a bar chart showing pinned/unpinned vortices depending on tilt. Because of this, I want each bar to represent one vortex, and the y-axis to be the tilt. Currently I have this code, ...
Score of -4
0 answers
58 views
Moving from legacy docker / uWSGI / Flask to new best practice [closed]
Years ago (2015-2020) I created a few hobby projects. The setup was extremely simple via:
tiangolo/uwsgi-nginx-flask:latest docker image, a slim docker image with a production ready webserver
simple ...
Score of 0
1 answer
181 views
Why can a parameterized class be instantiated?
I have this generic class:
class Box[T]:
def __init__(self, val: T):
self.val = val
In Python <3.12, that would be written:
from typing import TypeVar, Generic
T = TypeVar('T')
class ...
Score of 0
2 answers
114 views
Python API returns 8 and 22 instead of dates and symbols when selecting individual columns
I query a DFS table from Python. select * gives me correct dates and tickers, but as soon as I list the columns, TIME turns into 8 and CODE turns into 22 — the numeric columns are fine.
raw = session....
Score of 3
2 answers
115 views
Difference between three forms of instantiating a generic class in Python
I have this generic class in Python 3.12:
class Box[T]:
def __init__(self, val: T):
self.val = val
I can instantiate it in 3 ways:
box: Box[int] = Box(42)
box = Box[int](42)
box = Box(...
Score of 1
1 answer
129 views
Is there a way to use lazy imports in backwards-compatible code?
I'm writing some code that I want to make use of lazy imports, which were introduced in Python 3.15. However, I want the code to run fine on Python < 3.15 too, albeit without lazy imports.
Just ...
Score of -6
0 answers
93 views
Storing items in classes in python game development [closed]
Is there a way to make multiple copies of a class without specifying the variable name? Like how scratch has a "make clone of self" block. What I want is for there to be multiple items, so I ...
Score of 5
2 answers
112 views
Why does attrs treat a frozen attrs class differently from a frozen attrs field [duplicate]
I have these two attrs classes in Python:
import attrs
@attrs.define(frozen=True)
class FooA:
x: int
@attrs.define
class FooB:
x: int = attrs.field(on_setattr=attrs.setters.frozen)
In #1, ...
Score of -2
2 answers
135 views
Looking for a practical example where making a super call in the body of __init__ method of a metaclass makes a difference
Consider the following class Point and its metaclass PointMeta. What happens if I omit the super call in __init__ method of PointMeta class, is there any difference in behavior?
class PointMeta(type):
...
Score of 2
1 answer
135 views
Do I need a try/finally clause when calling cv2.VideoCapture.release()?
I'm learning how to capture video from camera using opencv for Python. The official tutorial provides the following example (modified):
import cv2 as cv
cap = cv.VideoCapture(0)
if not cap.isOpened():...
Score of -5
0 answers
133 views
Dog Bark Emotion Analysis: Should I include a breed classification pre-model? [closed]
I am a Computer Science student working on a project that analyzes dog barks to determine the underlying emotion.
Aside from the complex data collection process (recording barks and their associated ...
Score of -5
1 answer
254 views
Python 2 vs. Python 3: what does "not backward compatible" mean exactly?
According to Wikipedia:
Python 3.0 was released on 3 December 2008, and was a major revision and not completely backward-compatible with earlier versions, with some new semantics and changed syntax.
...