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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:51:20+00:00 2026-05-11T07:51:20+00:00

I am trying to organize some modules for my own use. I have something

  • 0

I am trying to organize some modules for my own use. I have something like this:

lib/   __init__.py   settings.py   foo/     __init__.py     someobject.py   bar/     __init__.py     somethingelse.py 

In lib/__init__.py, I want to define some classes to be used if I import lib. However, I can’t seem to figure it out without separating the classes into files, and import them in__init__.py.

Rather than say:

    lib/       __init__.py       settings.py       helperclass.py       foo/         __init__.py         someobject.py       bar/         __init__.py         somethingelse.py  from lib.settings import Values from lib.helperclass import Helper 

I want something like this:

    lib/       __init__.py  #Helper defined in this file       settings.py       foo/         __init__.py         someobject.py       bar/         __init__.py         somethingelse.py  from lib.settings import Values from lib import Helper 

Is it possible, or do I have to separate the class into another file?

EDIT

OK, if I import lib from another script, I can access the Helper class. How can I access the Helper class from settings.py?

The example here describes Intra-Package References. I quote ‘submodules often need to refer to each other’. In my case, the lib.settings.py needs the Helper and lib.foo.someobject need access to Helper, so where should I define the Helper class?

  • 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. 2026-05-11T07:51:20+00:00Added an answer on May 11, 2026 at 7:51 am
    1. ‘lib/‘s parent directory must be in sys.path.

    2. Your ‘lib/__init__.py‘ might look like this:

      from . import settings # or just 'import settings' on old Python versions class Helper(object):       pass 

    Then the following example should work:

    from lib.settings import Values from lib import Helper 

    Answer to the edited version of the question:

    __init__.py defines how your package looks from outside. If you need to use Helper in settings.py then define Helper in a different file e.g., ‘lib/helper.py‘.

     . |   `-- import_submodule.py     `-- lib     |-- __init__.py     |-- foo     |   |-- __init__.py     |   `-- someobject.py     |-- helper.py     `-- settings.py  2 directories, 6 files 

    The command:

    $ python import_submodule.py 

    Output:

    settings helper Helper in lib.settings someobject Helper in lib.foo.someobject  # ./import_submodule.py import fnmatch, os from lib.settings import Values from lib import Helper  print for root, dirs, files in os.walk('.'):     for f in fnmatch.filter(files, '*.py'):         print '# %s/%s' % (os.path.basename(root), f)         print open(os.path.join(root, f)).read()         print   # lib/helper.py print 'helper' class Helper(object):     def __init__(self, module_name):         print 'Helper in', module_name   # lib/settings.py print 'settings' import helper  class Values(object):     pass  helper.Helper(__name__)   # lib/__init__.py #from __future__ import absolute_import import settings, foo.someobject, helper  Helper = helper.Helper   # foo/someobject.py print 'someobject' from .. import helper  helper.Helper(__name__)   # foo/__init__.py import someobject 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to jump through some hoops to organize data in a special way.
I am trying to find some information how to organize permissions for silverlight application
I have a bunch of divs I'm trying to organize here. The ones I'm
I have Python nested list that I'm trying to organize and eventually count number
As documented here: http://www.jblotus.com/2011/05/24/keeping-your-handlebars-js-templates-organized/ I am trying to use this function: ( function getTemplateAjax(path,
I am trying to organize my JavaScript. What I would like to do is
i am trying to organize my photos and create some ajax front end. I
I've been trying to get my own opinion about this issue but could not,
I have been trying to write a macro (in steps) to organize the results
I am trying to add some shortcut handlers like Ctrl+B in my Silverlight application.

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.