Questions tagged [pyobject]

This is a type which contains the information Python needs to treat a pointer to an object as an object.

Definition

All object types are extensions of this type. This is a type which contains the information Python needs to treat a pointer to an object as an object. In a normal “release” build, it contains only the object’s reference count and a pointer to the corresponding type object. It corresponds to the fields defined by the expansion of the PyObject_HEAD macro.

Documentation

Common Object Structures

70 questions
58
votes
7 answers

Python: get string representation of PyObject?

I've got a C python extension, and I would like to print out some diagnostics. I'm receiving a string as a PyObject*. What's the canonical way to obtain a string representation of this object, such that it usable as a const char *?
Mark Harrison
  • 297,451
  • 125
  • 333
  • 465
24
votes
1 answer

Check if PyObject is None

I would just like to check if a PyObject that I have is None. I naively expected that any None Pyobject * returned from a function would be a NULL pointer, but that doesn't seem to be the case. So: how do I check if a PyObject * of mine points to a…
Matteo Monti
  • 8,362
  • 19
  • 68
  • 114
7
votes
1 answer

Using Py_BuildValue() to create a list of tuples in C

I am trying to use Py_BuildValue() to create a list of tuples in C. What I am trying to build would look like this: [ (...), (...), ... ] I don't know the amount of tuples to create at compilation, so I can't use some static amount here.…
ComputerLocus
  • 3,448
  • 10
  • 47
  • 96
6
votes
1 answer

Pickling a Python Extension type defined as a C struct having PyObject* members

I am running C++ code via Python and would like to pickle an extension type. So I have a C++ struct (py_db_manager) containing pointers to a database object and a object manager object (both written in C++) that I wrapped with a python type object…
octi
  • 1,470
  • 1
  • 17
  • 28
6
votes
1 answer

Julia: Converting PyObject to an Array

In Julia, I am calling a Python module pandas_datareader to download data from the web: using PyCall @pyimport datetime @pyimport pandas_datareader.data as web gdp = web.DataReader("GDPCA","fred",start=datetime.datetime(1929,1,1)) The variable gdp…
Marek
  • 61
  • 1
  • 4
5
votes
3 answers

how to deal with the PyObject* from C++ in Python

I create DLL wrote in C++ , the exporting function returns PyObject * .Then I use ctypes to import the DLL in Python . Now , how can I get the real PyObject ?? here's some part of c++ code: PyObject* _stdcall getList(){ PyObject * PList =…
Aha_1024
  • 61
  • 1
  • 4
5
votes
2 answers

How can I use PyObject_IsInstance with a non-builtin class as second argument?

In C/C++, I want to see if a PyObject is an instance. Unfortunately, the PyInstance_Check macro doesn't work with new-style classes. So, according to forums posts that I read, PyObject_IsInstance could solve the problem. However, all the examples…
GDICommander
  • 1,273
  • 3
  • 15
  • 27
4
votes
2 answers

How to determine struct used to declare the instance layout of PyObject?

I'm writing Python 3 extensions in C++ and I'm trying to find a way to check if a PyObject is related to a type (struct) defining its instance layout. I'm only interested in static-size PyObject, not PyVarObject. The instance layout is defined by a…
mloskot
  • 37,086
  • 11
  • 109
  • 136
4
votes
3 answers

the attribute of ctypes.py_object

I am trying to creating a python array and have problems with the following code def __init__(self, size): assert size>0, "Array size must be > 0" self._size = size # Create the array structure using the ctypes module. arraytype =…
Charlotte
  • 43
  • 1
  • 4
4
votes
0 answers

ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or RSP based frame Undefined symbols for architecture x86_64:

I am trying to include Python.framework into iOS from here. I got the following errors: ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or RSP based frame Undefined symbols for architecture x86_64: …
4
votes
1 answer

Custom PyObject by inheritance in C++

Long term python programmer, first time C++ extension writer guy. Anyways, for fun, I'm trying to create a linked list module for python in C++. Here's my code #include #include using namespace std; template…
James Robert Albert
  • 404
  • 1
  • 5
  • 13
4
votes
1 answer

how does Cpython implement its type Objects, i.e. type's type is always type?

I understand that everything in python is an Object and that the 'type' (or class) of these object is 'type'. Plus the type of type is also type itself. (as explained nicely here) What I do not understand is how is this circular reference…
mayank
  • 186
  • 3
  • 12
3
votes
1 answer

python bytearray to C++ object

I'm wondering if I could get some help. For context, I'm using some C++ libraries to generate some large (think hundreds of Mb) objects that I want to send over a network from a server to a client. On the server, I've got the following: PyObject* …
IanQ
  • 1,831
  • 5
  • 20
  • 29
3
votes
1 answer

C++ callback with python through SWIG when the function takes non-trivial arguments?

I just read the following section of the "SWIG and Python" tutorial: http://www.swig.org/Doc1.1/HTML/Python.html#n11 I understand what they do in the example, basically you write a C function that calls python. However, the example provided takes…
cemulate
  • 2,305
  • 1
  • 34
  • 48
3
votes
1 answer

Python C API: Problems trying to build a dictionary

I'm trying to build a Python dictionary using the C API but it seems it's not possible (Py_BuildValue returns a NULL object) to use a PyObject* as value. I have a situation like the following: #include ... PyObject *myList =…
ggagliano
  • 1,004
  • 1
  • 11
  • 27
1
2 3 4 5