Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6093271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:32:26+00:00 2026-05-23T12:32:26+00:00

I am developing an interface so that Python programs can call into an existing

  • 0

I am developing an interface so that Python programs can call into an existing C++ library. If I understand correctly, such an interface (and the C++ library) should be imported as a module, say abc. The types in the interface are defined as static variables on the C++ side of the interface, and registered with Python using the following sequence:

void PythonRegistrationData::RegisterType(PyObject* module, PyTypeObject* type)
{
    if (type->ob_refcnt < 2)
    {
        if (type->tp_base != NULL)
            RegisterType(module, type->tp_base);
        Py_INCREF(type);
        if (PyType_Ready(type) != 0)
            throw GPython::DummyError();
        PyModule_AddObject(module, type->tp_name, as<PyObject>(type));
    }
}

(The recursion is to ensure that base classes are registered before the derived class. The module has been created earlier.) According to the C-API docs, “For statically allocated type objects, the tp_name field should contain a dot.”; for this reason, I initialize tp_name with "abc.MyType". When I do this, after loading the module, I get 'module' object has no attribute 'MyType' when I try to use the type (e.g. x = abc.MyType(), having done import abc before). If I use just "MyType", it seems to work, but this seems to contradict both the official documentation and the examples in the tutorial.

So what is the exact meaning of the tp_name field, and what should it really contain? And what is the effect of my not putting the module name in it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:32:27+00:00Added an answer on May 23, 2026 at 12:32 pm

    By doing

    PyModule_AddObject(module, type->tp_name, as<PyObject>(type));
    

    you are adding the type to the module (which means setting an attribute) using “abc.MyType” as the attribute name. Which means you would need to access it using getattr(abc, 'abc.MyType') if you wanted to access it on the abc module (you can’t access attributes with dots in the name directly.) You should set the tp_name to the “qualified” name (with abc. in front of it), you just shouldn’t use the tp_name as the attribute name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing in python a file class that can read and write a
I have this JUnit test that I need help developing a Interface and Class
I'm starting a new project which involves developing an interface for a machine that
I'm developing a site that's pretty lightweight on the interface and mostly database driven
I'm developing a an eclipse plugin that uses an SWT interface. I need to
I am developing a web-based user interface that plots some data from a database
I'm developing a web application that needs to interface with a MySQL database, and
I am developing a live-action tag game (called DeTag) that uses a web interface
I am developing a class library that will be used in several projects. In
I'm developing a Python/ObjC application and I need to call some methods in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.