473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to get PyTypeObject from PyObject?

I want to check the type of an object, right now I am doing
strcmp( object->ob_type->tp_name, "MyClass")

Which seems slow, is there a way I can find the pointer to the global
PyTypeObject for MyClass, and then just call PyObject_TypeCheck?

Thanks

Aug 25 '08 #1
1 5521
chris <cg******@gmail.comwrites:
I want to check the type of an object, right now I am doing
strcmp( object->ob_type->tp_name, "MyClass")

Which seems slow, is there a way I can find the pointer to the
global PyTypeObject for MyClass, and then just call
PyObject_TypeCheck?
Simply get the PyObject that corresponds to MyClass using
PyObject_GetAttr on the module (or in some other way). If MyClass is
a new-style class, you can cast it to PyTypeObject and compare that to
object->ob_type.

For questions about the C API, see the capi-sig,
http://mail.python.org/mailman/listinfo/capi-sig
Aug 25 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nikolai Kirsebom | last post by:
I'm using BOOST to integrate Python into our application. Could someone tell me how I get hold of the C++ object (pointer to the object instance) from a PyObject *. Example: I have defined and...
1
by: Mike Hoegeman | last post by:
I'm in a situation where -- i have a PyObject * that is a instance of an object -- i need to access a subobject of that (PyObject *) that is described to me as a dotted string, e.g.: ...
5
by: Christian Seberino | last post by:
In c extension what is easiest way to build a (PyObject) list from an array of doubles? I don't think I can do "return Py_BuildValue(...) to make a list from an array can I??? How else can I...
0
by: Olivier Sessink | last post by:
Hi all, I want to make a value available to the global namespace of an embedded python interpreter. Several functions of the Python/C API feature a PyObject *globals and a PyObject *locals, so...
0
by: Gabriel de Dietrich | last post by:
Hi, I'm doing my first project on embedding and then extending Python in an application. The idea is to import a set of C++ plug-ins into Python and then be able to run a script that uses these...
11
by: seberino | last post by:
Suppose a C extension locally built an array of PyObject* 's as follows... my_array = malloc(n * sizeof(PyObject*)); for (i = 0; i < n; i++) { my_array = PyList_New(0); } Q1: Must I do a...
0
by: Pradnyesh Sawant | last post by:
Hello, i have the following code: ################################################################# import time import sys from PyQt4 import QtGui, QtCore class Counter(QtCore.QThread): def...
1
by: Allen | last post by:
I have the PyObject pointers, and want to set different type of values to them. For example, INT8 nValue1 = 0; INT16 nValue2 = 1; FLOAT32 fValue = 1.0f; PyObject* var1 <= nValue1
0
by: Borse, Ganesh | last post by:
Hi, My following code is failing with an error of "isSizeSmall not function or callable" //--------------------------------------------------- char szExpr; memset(szExpr,'\0',sizeof(szExpr));...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.