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

  • SEARCH
  • Home
  • 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 7799821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:25:50+00:00 2026-06-02T00:25:50+00:00

I have a C++ class called Foo. If I follow the Cython C++ tutorial

  • 0

I have a C++ class called Foo. If I follow the Cython C++ tutorial I will need to call the Python class differently, PyFoo for example.
However I really need to call the Python class Foo as well. How to do that efficiently?

Edit: I’m trying to interface an existing C++ library that was previously interfaced with Boost Python. For different reasons I would like to test Cython instead.
Since with Boost:Python Python classes were called with the same name as in C++, I would like to continue with this naming convention. It’s not a Python (CPython) requirement to call classes differently, but it seems to be imposed by Cython, at least in the tutorial.

I can of course use a pure python module to define a Foo class that calls PyFoo, but this seems both boring and inefficient.

  • 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-06-02T00:25:52+00:00Added an answer on June 2, 2026 at 12:25 am

    There are two ways to handle this.

    1. Declare C++ class with an alternate name; original name has to be specified in double quotes:

      cdef extern from "defs.h" namespace "myns":
          cdef cppclass CMyClass "myns::MyClass":
              ...
      

      Then you can use MyClass for your python class and refer to C++ declaration as CMyClass.

      Note that original name has to include the namespace explicitly (if it is namespaced).
      Cython template arguments (when present) should go after an alternate name declaration.

    2. Declare your C++ classes in a separate .pxd file, named differently from your .pyx file, then import them with cimport.

      In cpp_defs.pxd:

      cdef extern from "defs.h" namespace "myns":
          cdef cppclass MyClass:
              ...
      

      In py_wrapper.pyx:

      cimport cpp_defs as cpp
      
      cdef class MyClass:
          cpp.MyClass *_obj
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a class called Foo . This class will be modified by
I have a class called Foo with a constructor that needs arguments, and a
I have a class called Foo that has a function that looks like the
I have a class called Foo that defines a list of objects of type
Say I have a javascript function/class called Foo and it has a property called
My situation is essentially this: I have a class called Foo which has dependencies
Let's say I have a class in my web app called class Foo. It
I have a class called Foo that looks like this: class Foo < ActiveRecord::Base
Let's say I have a class called 'foo' in namespace abc... namespace abc {
Assume I have a user defined Java class called Foo such as: public class

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.