pointers

What is the pythonic way to test whether two objects are the same, not just equal

What is the pythonic way to test whether two objects are the same, not just equal Question: My solution has been to make the object’s address into a string, which should always be unique. Below is a case where it works both ways, comparing the objects and comparing the values of str(object_a) and str(object_b). >>> …

Total answers: 2

Passing 3-dimensional numpy array to C

Passing 3-dimensional numpy array to C Question: I’m writing a C extension to my Python program for speed purposes, and running into some very strange behaviour trying to pass in a 3-dimensional numpy array. It works with a 2-dimensional array, but I’m sure I’m screwing something up with the pointers trying to get it to …

Total answers: 4

Are Python variables pointers? Or else, what are they?

Are Python variables pointers? Or else, what are they? Question: Variables in Python are just pointers, as far as I know. Based on this rule, I can assume that the result for this code snippet: i = 5 j = i j = 3 print(i) would be 3. But I got an unexpected result for …

Total answers: 9

Executing assembler code with python

Executing assembler code with python Question: I want to execute assembly code inside a python script. Is that possible? In C programming would be like this static inline getesp(){ __asm__(“mov %esp, %eax”); } But how to do that with Python? Is it possible? Asked By: Yuda Prawira || Source Answers: Python does not support this …

Total answers: 7

Pointers in Python?

Pointers in Python? Question: I know Python doesn’t have pointers, but is there a way to have this yield 2 instead >>> a = 1 >>> b = a # modify this line somehow so that b “points to” a >>> a = 2 >>> b 1 ? Here’s an example: I want form.data[‘field’] and …

Total answers: 10

Pointers and arrays in Python ctypes

Pointers and arrays in Python ctypes Question: I have a DLL containing a C function with a prototype like this: int c_read_block(uint32 addr, uint32 *buf, uint32 num); I want to call it from Python using ctypes. The function expects a pointer to a chunk of memory, into which it will write the results. I don’t …

Total answers: 3

Simulating Pointers in Python

Simulating Pointers in Python Question: I’m trying to cross compile an in house language(ihl) to Python. One of the ihl features is pointers and references that behave like you would expect from C or C++. For instance you can do this: a = [1,2]; // a has an array b = &a; // b points …

Total answers: 11