Skip to main content
3 votes
2 answers
186 views

I am reading about Numerical promotion in numpy. I copy the main graph here: Based on the graph, this explanation: The input dtype with the higher kind determines the kind of the result dtype. The ...
17 votes
1 answer
4k views

The Python Doc for Comparisons says: Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z, except that y is evaluated only once (but in both cases z ...
3 votes
0 answers
99 views

Given some object o in Python, how do I get a list of all instance (not class) attributes which that object has? For most objects, this is simple: just check o.__dict__, either directly or via vars(). ...
4 votes
2 answers
156 views

Why is the following line valid Python code? code = compile('l = list(1, 2, 3, 4, 5)', '', 'exec') The documentation says Using the type constructor: list() or list(iterable) I can even write the ...
5 votes
3 answers
241 views

I have two functions with 100% identical (and lengthy) sets of arguments, but slight variations in internal code. I'd like to use the first-class-object nature of functions to reuse the argument set, ...
0 votes
2 answers
134 views

I'm running the following code both remotely on a linux machine via ssh, and on the same linux machine as a Jupyter notebook accessed through a browser. import cv2 import pdf2image def minimalFun(...
Advice
1 vote
8 replies
141 views

I am curious about the design philosophy of Python's function arguments. Currently, we have *args to collect positional arguments into a tuple and **kwargs to collect keyword arguments into a ...
Advice
3 votes
6 replies
140 views

Context In Fluent Python (2nd ed.) by Luciano Ramalho, Example 2-16 shows that: >>> t = (1, 2, [30, 40]) >>> t[2] += [50, 60] results in: t becoming (1, 2, [30, 40, 50, 60]) a ...
388 votes
6 answers
117k views

This question is motivated by my another question: How to await in cdef? There are tons of articles and blog posts on the web about asyncio, but they are all very superficial. I couldn't find any ...
0 votes
0 answers
55 views

When I override equality on a class in any language I have to be careful not to create an inconsistent hash function. Python 3 and Python 2 with old-style classes help here by deleting the __hash__ ...
2 votes
1 answer
308 views

I started wondering how CPython can tell the difference between None as a default argument and None as a specified argument. For example, dict.pop() will throw a KeyError if the key doesn't exist. ....
37 votes
3 answers
8k views

I'm currently trying to understand the mechanism behind the hash function defined for Python's built-in frozenset data type. The implementation is shown at the bottom for reference. What I'm ...
2 votes
0 answers
117 views

I am trying to link a custom version of sqlite3 when building Python, but there is an error when compiling Python: /usr/bin/install: cannot stat 'Modules/_sqlite3.cpython-313-x86_64-linux-gnu.so': No ...
1305 votes
14 answers
442k views

What is the purpose of __slots__ in Python — especially with respect to when I would want to use it, and when not?
0 votes
2 answers
132 views

I'm encountering a peculiar issue when using Python's exec function within scripts that are run across different Git worktrees. Specifically, I've observed that the behavior of exec (and by extension, ...

15 30 50 per page
1
2 3 4 5
52