cpython Questions
6
Solved
I am trying to install OpenCV from Unofficial Windows Binaries for Python Extension Packages.
I downloaded the following file : opencv_python‑3.4.3‑cp37‑cp37m‑win_amd64.whl,
and when I did pip i...
7
Solved
I want to show someone how using is instead of == to compare integers can fail. I thought this would work, but it didn't:
>>> import copy
>>> x = 1
>>> y = copy.deepcopy...
4
Solved
In CPython, the builtin-function id(x) returns the memory address of x.
Is it possible to reverse this ?
Something like object_by_memoryadress(id(x)) == x.
Update: The reason I need this is, beca...
1
The documentation is not very informative (at least for me):
opcode:: RESUME (context)
A no-op. Performs internal tracing, debugging and optimization
checks.
The context oparand consists of two pa...
Trichinopoly asked 17/11, 2023 at 16:19
1
Solved
Normally, if you try to pass multiple values for the same keyword argument, you get a TypeError:
In [1]: dict(id=1, **{'id': 2})
--------------------------------------------------------------------...
2
Solved
I am thinking of how the in operator implement, for instance
>>> s1 = 'abcdef'
>>> s2 = 'bcd'
>>> s2 in s1
True
In CPython, which algorithm is used to implement the st...
3
Solved
EDIT:
I have created a module to provide this functionality. It might not be that great but it can be obtained here.
Original Question
I need to be able to parse format strings (as specified by the...
Duchy asked 14/6, 2017 at 17:53
6
Solved
how can I load a c# dll in python?
Do I have to put some extra code in the c# files? (like export in c++ files)
I don't want to use IronPython. I want to import a module to Python!
Superheterodyne asked 16/1, 2010 at 15:38
2
Solved
Timing results in Python 3.12 (and similar with 3.11 and 3.13 on different machines):
When x = None:
13.8 ns x is None
10.1 ns if x is None: pass
When x = True:
13.9 ns x is None
11.1 ns if x is N...
Rawdin asked 26/3, 2024 at 14:12
2
I am attempting to take the source code of a function, add code to it, and then put it back in the original function.
Basically like so:
new_code = change_code(original_code)
throwaway_module = M...
Posthumous asked 9/2, 2019 at 1:26
1
Solved
Called with n = 10**8, the simple loop is consistently significantly slower for me than the complex one, and I don't see why:
def simple(n):
while n:
n -= 1
def complex(n):
while True:
if not ...
Kilkenny asked 10/12, 2023 at 13:17
3
Solved
This is disassembly of a list comprehension in python-3.10:
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or &...
Gentille asked 16/11, 2023 at 12:53
4
Solved
While trying to use Python's exec statement, I got the following error:
TypeError: exec: arg 1 must be a string, file, or code object
I don't want to pass in a string or a file, but what is a code...
1
Is python gc.collect() a stop-the-world (STW) garbage collector?
If it is a STW garbage collector, where and when to stop the world?
I know python uses deterministic reference counting, and this...
2
t = (1,2,3)
t1 = (1,2,3)
print(id(t))
print(id(t1))
The above lines of code gives the same addresses in script mode in Python, but in interactive mode it outputs different addresses. Can anyone e...
Ecker asked 11/6, 2020 at 15:20
5
Solved
I'm creating a C++ extension for python. It creates a module parent that contains a sub-module child. The child has one method hello(). It works fine if I call it as
import parent
parent.child.hell...
Jawbone asked 10/5, 2023 at 20:41
2
Solved
I have a C extension that is called from my multithreaded Python application. I use a static variable i somewhere in a C function, and I have a few i++ statements later on that can be run from diff...
Schuler asked 2/2, 2017 at 15:38
1
Solved
Not sure if it's off topic but don't know any better place to ask.
In cpython there was a very giant switch case statement for executing each opcode.
This switch case previously was placed in the _...
1
Solved
I am trying to leak memory from my C-extension forcefully.
The code for the below is
Pyobect* myfunc(PyObject* self, PyObject* args)
{
static int i = 213123;
PyObject* temp = PyLong_FromLong(i); ...
Gerhardine asked 27/3, 2023 at 10:49
1
Solved
In CPython 3.11, the following code returns very large reference counts for some objects. It seems to follow pre-cached objects like integers -5 to 256, but CPython 3.10 does not:
Python 3.11.2 (ta...
Provide asked 17/3, 2023 at 3:39
1
Solved
1
Solved
I'm trying to implement an algorithm in the form of the C programming language into my system that runs using the python programming language. I'm trying to implement the Python C API with the inte...
Wayfaring asked 1/2, 2023 at 6:33
0
I have a C++ script that I run in Visual studio 2022 on windows 10 and where I include the python module. In the code I import numpy in a for-loop. The code executes fine the first round, but in th...
1
Solved
When I use bitwise and operator(&) with the number of 1 to find out if a number x is odd or even (x & 1), does the interpreter change the binary representation of 1 according to the binary ...
Contextual asked 18/12, 2022 at 22:6
1
Solved
If we look at the resize behavior for sets under 50k elements:
>>> import sys
>>> s = set()
>>> seen = {}
>>> for i in range(50_000):
... size = sys.getsizeof(s)...
Nighttime asked 28/11, 2022 at 22:8
1 Next >
© 2022 - 2025 — McMap. All rights reserved.