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 8287815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:08:55+00:00 2026-06-08T12:08:55+00:00

In a Python package directory of my own creation, I have an __init__.py file

  • 0

In a Python package directory of my own creation, I have an __init__.py file that says:

from _foo import *

In the same directory there is a _foomodule.so which is loaded by the above. The shared library is implemented in C++ (using Boost Python). This lets me say:

import foo
print foo.MyCppClass

This works, but with a quirk: the class is known to Python by the full package path, which makes it print this:

foo._foo.MyCppClass

So while MyCppClass exists as an alias in foo, foo.MyCppClass is not its canonical name. In addition to being a bit ugly, this also makes help() a bit lame: help(foo) will say that foo contains a module _foo, and only if you say help(foo._foo) do you get the documentation for MyCppClass.

Is there something I can do differently in __init__.py or otherwise to make it so Python sees foo.MyCppClass as the canonical name?

I’m using Python 2.7; it would be great if the solution worked on 2.6 as well.

  • 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-08T12:08:56+00:00Added an answer on June 8, 2026 at 12:08 pm

    I had the same problem. You can change the module name in your Boost.Python definition:

    BOOST_PYTHON_MODULE(_foo)
    {
      scope().attr("__name__") = "foo";
      ...
    }
    

    The help issue is a separate problem. I think you need to add each item to __all__ to get it exported to help.

    When I do both of these, the name of foo.MyCppClass is just that — foo.MyCppClass — and help(foo) gives documentation for MyCppClass.

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

Sidebar

Related Questions

If I have a Python module implemented as a directory (i.e. package) that has
I have a python package that needs to pull in settings from my project
Possible Duplicate: Python package structure Hello, I'm looking to import a python file that
I have following directory structure: / package/ subpackage/ __init__.py file.py __init__.py file.py main.py /package/subpackage/__init__.py
Looking in my /usr/local/lib/python.../dist-package directory, I have .egg directories and .egg files. Why does
I am wondering why the directory (subpackage) that holds submodules in a python package
Is there any way to create a virtual import path in Python? My directory
I have the python package in Cygwin on Windows 7. However, typing python -V
I've got a python package which outputs considerable help text from: help(package) I would
I'm attempting to make a python package of the following hierarchy: \standard \__init__.py \text.txt

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.