2,204,643 questions
Score of -2
0 answers
18 views
Pygbag: NotImplementedError: set_timer is not implemented on WASM yet
pygame-ce 2.5.7 (SDL 2.28.4, Python 3.12.12)
\>>> Task exception was never retrieved
future: <Task finished name='main' coro=<main() done, defined at <console>:3> exception=...
Score of -6
2 answers
137 views
Python discount function returns negative value and passes all linters, mypy, bandit and unit tests [closed]
I have this pricing function in a Python e-commerce application:
def apply_discount(price, discount):
return price * (1 - discount)
It works correctly for normal inputs:
apply_discount(100, 0....
Score of -2
1 answer
71 views
When installing requests with UV, VS code cannot find requests module, but the script runs successfully from the command line
When installing requests with UV, VS code cannot find requests module, but the script runs from the command line.
uv python list
cpython-3.12.3-linux-x86_64-gnu /usr/bin/python3.12
...
Score of -2
1 answer
111 views
Send an email from Outlook account using Python [closed]
I'm trying to send an email from my Outlook account to Gmail using Python's smtplib. I set up SMTP with Office 365 (smtp.office365.com:587) and credentials but get a "550 5.7.1 Client does not ...
Score of 1
0 answers
96 views
How to run a process that survives after parent process dies? subprocess.CREATE_NEW_PROCESS_GROUP is not working
I use VScode on Windows 10.
I run a subprocess using the subprocess module. but it closes if I kill the parent process, whether I kill it with VScode or with os.kill(os.getpid()).
I tried many things ...
Score of 1
1 answer
98 views
Why isn't my type checker (Pyright) complaining about a clear type violation?
Why isn't Pyright complaining about this? msg: Any is not a Message. (Pylance 2026.3.1)
import asyncio
from dataclasses import dataclass
import json
@dataclass(frozen=True, slots=True)
class Message:
...
Score of -10
0 answers
126 views
I can't figure out how to make this BMI calculator work [closed]
# title
print('This is a BMI calculator')
# this asks what sytem to use
imp_or_met = input('Metric or imperial? (all caps) ')
# this is the code to get you BMI using metric values
if imp_or_met == '...
Score of 0
1 answer
131 views
Best practice for (simple) searching item in a list
Typically, I would obtain/return an item from a list of items like so:
def search_in_list(search_id):
for item in my_list:
if item['id'] == search_id:
return item
return ...
Score of 4
2 answers
184 views
How to type-hint a function that returns as many values as in its input?
I have a function that takes one or more arguments and returns the same number of values. For a single input value, it returns just one value, not a size one tuple, for multiple values it returns a ...
Score of -5
0 answers
81 views
Buildozer cannot build APKs again [closed]
I have been using buildozer==1.5.0 to build my APKs for sometime now since I have understood the basics. I use Arch Linux and I have learnt to build a specific Virtual Environment(which the one I have ...
Score of 0
0 answers
62 views
PySide6 Custom widget with Enum property
In PySide6, I'm trying to create a custom widget and register it as a plugin in Qt Designer. My widget has one attribute that is an enum.
It displays correctly in Qt Designer, I can change the value ...
Score of 5
1 answer
149 views
Why can moving an await change whether a Python object remains reachable, even when the object has no explicit strong reference?
I am trying to understand a surprising difference in object lifetime in Python asyncio.
Consider this simplified example:
import asyncio
import gc
import weakref
class Resource:
def __init__(self, ...
Score of -3
1 answer
123 views
Python Library/Module Won't Import While Others Do
Mac os Sequoia 15.6
I installed the exifread library using pip as well as conda. In Anaconda Navigator it shows as installed. Using a terminal window I type in:
pip3 show exifread
and it returns
/opt/...
Score of -5
1 answer
189 views
Opened .txt file seems to be empty after a for in function [duplicate]
edit: sorry I wasn't up to the standards, I thought I had everything in order. That said, thanks for the people that answered and helped, file.seek(0) worked! I really couldn't find anything online ...
Score of 2
1 answer
135 views
How can I make numpy arrays the same shape before doing conditional computations?
Let's say I have a conditional calculation like this
import numpy as np
def foo(a, b, c):
if a <= 0 or c == 0:
return foo_special(a, b, c)
return foo_normal(a, b, c)
def ...