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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:38:19+00:00 2026-06-02T05:38:19+00:00

I’m considering a package implementation set up like this: wordproc __init__.py _generic.py gedit.py oofice.py

  • 0

I’m considering a package implementation set up like this:

wordproc
    __init__.py
    _generic.py
    gedit.py
    oofice.py
    word.py

_generic.py would have a class like this:

class WordProc (object):

    def __init__ (self):
        pass

    def createNewDoc (self):
        print "createNewDoc unimplemented in current interface"

    def getWordCount (self):
        print "getWordCount unimplemented in current interface"

    etc...

These could print out as shown, or raise errors. App-specific modules would just be copies of _generic.py with the WordProc classes deriving from _generic.WordProc. In this way, functionality could be implemented iteratively over time, with messages about unimplemented things simply raising alerts.

I’m imagining that __init__.py could look for the following things (listed in order) to figure out which module to use:

  1. a wordproc module variable
  2. a settings file in the path
  3. a wordproc environment variable
  4. a function that attempts to determine the environment
  5. a default in __init__.py (probably _generic.py)

I think 3 could be a function in each app’s module, or these could go into folders with particularly named environment test scripts (e.g. env.py), and __init__.py could loop over them.

I’d like then in any libraries that want to use wordproc to simply be able to do this:

import wordproc as wp

wp.createNewDoc()
etc...

What I don’t know is how to have wp resolve to the proper class in the proper module as determined by __init__.py. It doesn’t make sense to do this:

import wordproc.gedit as wp

This destroys the point of having __init__.py determine which module in wordproc to use. I need something like class inheritance, but on the module level.

  • 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-02T05:38:21+00:00Added an answer on June 2, 2026 at 5:38 am

    You can achieve your desired effect by writing __init__.py like this:

    1. Import the appropriate module first. See python docs on importlib.import_module or __import__ for help on dynamic imports.
    2. Instantiate the class from which you want to export methods
    3. Assign the instance methods to locals()
    # import appropriate module as mod depending on settings, environment
    # using importlib.import_module, or __import__
    
    __all__ = []
    
    _instance = mod.WordProc()
    for attr in dir(_instance):
        if not attr.startswith('_') and callable(getattr(_instance, attr)):
            locals()[attr] = getattr(_instance, attr)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.