questions

How to make my sprite go back to its original frame after changing in pygame

How to make my sprite go back to its original frame after changing in pygame Question: I’m a beginner when it comes to python and I’m making a pygame game and want to have the player’s sprite change to a different image frame when it goes up and down and return back to its original …

Total answers: 1

How do I set my own custom mapping to my combinations iterator in python?

How do I set my own custom mapping to my combinations iterator in python? Question: I’m coding in python and I have an iterator that iterates through all the possible combinations of a 45 character string. I am generating them one at a time and I have found that it generates from the smallest possible …

Total answers: 2

Measure execution time, but also in case of exceptions

Measure execution time, but also in case of exceptions Question: I am writing some code that I would like to add prometheus metrics. In the metrics we want to measure the time it took, but also in case a exception was raised. I ended up with this code, but it feels as if it can …

Total answers: 2

With Polars, how to concatenate list-of-string expression/column to string

With Polars, how to concatenate list-of-string expression/column to string Question: Here’s a naive solution of what I want to do using map_elements. How can I do this with only Polars functions? import polars as pl # Create a DataFrame with a column containing lists of strings df = pl.DataFrame({ "list_of_strings": [["a", "b", "c"], ["d", "e", …

Total answers: 1

Why doesn't import work when running the script from the console?

Why doesn't import work when running the script from the console? Question: In the file create_admin_user.py I write: from models import User, Role, Session At startup create_admin_user.py everything is fine from PyCharm, but when I run it from the terminal with the command python create_admin_user.py returns error: ModuleNotFoundError: No module named ‘models’ Here is my …

Total answers: 1

OCR and pytesseract detecting numbers in an image

OCR and pytesseract detecting numbers in an image Question: currentbid.png: I am trying to detect the number in this image and it gives me letters or the wrong number. This is my image i am trying to detect the number ive tried tons of stuff with greyscale and inversion using tesseract but nothing seems to …

Total answers: 1

How does typing.Type work in Python? When can variables be used as types?

How does typing.Type work in Python? When can variables be used as types? Question: I am using Python 3.11 and Pylance for this. class Dog: pass Example A: DogType: type[Dog] = Dog # type[Dog] AnotherDogType: type[DogType] = Dog # Error # ^^^^^^^ variable not allowed in type expression Example B: DogType = Dog # type[Dog] …

Total answers: 2

Docker image size is coming up to 9.75 G for Ubuntu with Python packages

Docker image size is coming up to 9.75 G for Ubuntu with Python packages Question: Here is my Dockerfile. The problem is that the Image size is 9.75gb FROM ubuntu:latest # Avoid warnings by switching to noninteractive ENV DEBIAN_FRONTEND=noninteractive RUN apt update && apt && ln -fs /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && dpkg-reconfigure –frontend noninteractive tzdata # …

Total answers: 2