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 ...
zabop's user avatar
  • 8,310
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(). ...
macdjord's user avatar
  • 683
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 ...
haferfleks's user avatar
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 ...
toliveira's user avatar
  • 1,883
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 ...
toliveira's user avatar
  • 1,883
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, ...
Tom Grundy's user avatar
  • 1,044
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, ...
user avatar
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 ...
Sherwin R's user avatar
  • 159
2 votes
0 answers
210 views

To be clear, I'm not suggesting anyone actually should import pkg.__init__ directly. This is to understand potential pitfalls if someone decides to convert a module-only distribution into a package, ...
dROOOze's user avatar
  • 4,289
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__ ...
julaine's user avatar
  • 2,792
3 votes
1 answer
225 views

Python docs on the dis module state that the length of a python bytecode instruction in CPython is 2 bytes (https://docs.python.org/3/library/dis.html) However, when I disassemble a function and look ...
Petras Purlys's user avatar
5 votes
2 answers
315 views

I am unable to find anything on the official Python documentation whether L[a:b] = L[c:d] creates a new (temporary) list for L[c:d] before the in-place modification of L. The tutorial says that: All ...
user29120650's user avatar
1 vote
0 answers
80 views

Since os is a module instead of a package, import os.path should fail. For comparison: >>> import os.sys Traceback (most recent call last): File "<python-input-0>", line 1, ...
Aemyl's user avatar
  • 2,457
2 votes
2 answers
182 views

I am wondering how self works under-the-hood in Python classes. My current limited understanding is that when a class is defined, e.g. class Foo: def __init__(self, x: int): self.x = x ...
FISR's user avatar
  • 293
1 vote
1 answer
203 views

My Python code stores millions of ids in various data structures, in order to implement a classic algorithm. The run time is good, but the memory usage is awful. These ids are ints. I assume that ...
SRobertJames's user avatar
  • 9,457

15 30 50 per page
1
2 3 4 5
52