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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:16:45+00:00 2026-05-14T14:16:45+00:00

I had never noticed the __path__ attribute that gets defined on some of my

  • 0

I had never noticed the __path__ attribute that gets defined on some of my packages before today. According to the documentation:

Packages support one more special
attribute, __path__. This is
initialized to be a list containing
the name of the directory holding the
package’s __init__.py before the code
in that file is executed. This
variable can be modified; doing so
affects future searches for modules
and subpackages contained in the
package.

While this feature is not often
needed, it can be used to extend the
set of modules found in a package.

Could somebody explain to me what exactly this means and why I would ever want to use 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-14T14:16:46+00:00Added an answer on May 14, 2026 at 2:16 pm

    This is usually used with pkgutil to let a package be laid out across the disk. E.g., zope.interface and zope.schema are separate distributions (zope is a “namespace package”). You might have zope.interface installed in /usr/lib/python2.6/site-packages/zope/interface/, while you are using zope.schema more locally in /home/me/src/myproject/lib/python2.6/site-packages/zope/schema.

    If you put pkgutil.extend_path(__path__, __name__) in /usr/lib/python2.6/site-packages/zope/__init__.py then both zope.interface and zope.schema will be importable because pkgutil will have change __path__ to ['/usr/lib/python2.6/site-packages/zope', '/home/me/src/myproject/lib/python2.6/site-packages/zope'].

    pkg_resources.declare_namespace (part of Setuptools) is like pkgutil.extend_path but is more aware of zips on the path.

    Manually changing __path__ is uncommon and probably not necessary, though it is useful to look at the variable when debugging import problems with namespace packages.

    You can also use __path__ for monkeypatching, e.g., I have monkeypatched distutils at times by creating a file distutils/__init__.py that is early on sys.path:

    import os
    stdlib_dir = os.path.dirname(os.__file__)
    real_distutils_path = os.path.join(stdlib_dir, 'distutils')
    __path__.append(real_distutils_path)
    execfile(os.path.join(real_distutils_path, '__init__.py'))
    # and then apply some monkeypatching here...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Somehow I never noticed until today that C++ supports nested classes. This surprised me
I noticed that I had a project named RemoteSystemTempFiles which I never have created.
I had never heard of persistent connections before, and I don't understand the advantages.
I had never had this error before, and I didn't move any file, or
Having been an imperative developer for some years now, I had never had the
I've been working for some time on (Java) Bytecode, however, it had never occurred
This is a strange one, I'm shocked I've never noticed it before. It works
I had an old view that was giving out some odd data when I
I was just reviewing some code and noticed someone had marked member as readonly
I've never had to use mysqli until today and cannot seem to get this

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.