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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:18:01+00:00 2026-06-08T18:18:01+00:00

I have a package structure as follows: mypackage __init__.py mymodule.py I put some constant

  • 0

I have a package structure as follows:

mypackage
  __init__.py
  mymodule.py

I put some “constant” declarations in __init__.py for example:

DELIMITER='\x01'

However, the code in the mymodule.py can’t access DELIMITER unless I add:

from __init__ import *

To the top of the mymodule.py file. I suppose I missed a concept here. Is it that whatever is declared in __init__.py doesn’t get read into memory until it is accessed via an import statement? Also, is this a typical type of thing to put into the __init__.py file?

  • 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-08T18:18:02+00:00Added an answer on June 8, 2026 at 6:18 pm

    Python does run the code in __init__.py when the package is imported, which allows some initialization to be done. However, just because it is run does not mean that you have access to the variables in it from within other modules.

    For example:

    testpackage
        __init__.py
        testmod.py
    

    Let’s say __init__.py has the code print "Initializing __init__", and testmod.py has print "Initializing testmod". In that case, importing testpackage or testmod would cause the initialization code to be run:

    dynamic-oit-vapornet-c-499:test dgrtwo$ python -c "import testpackage"
    Initializing __init__
    dynamic-oit-vapornet-c-499:test dgrtwo$ python -c "from testpackage import testmod"
    Initializing __init__
    Initializing testmod
    

    It doesn’t, however, give testmod.py access to the variables from __init__.py. This has to be done explicitly.

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

Sidebar

Related Questions

I have next package structure webService.ear -- dependency.jar -- some.class Can I remove some.class
Say i have this this structure. MyApp ├── main.py └── package ├── __init__.py ├──
I have a directory structure as follows: | main.py | scripts |--| __init__.py |
In Eclipse I have two projects with the same package structure. In one of
Okay so, I have this project structure: package A.B class SuperClass (this class is
I have a package like this package/ __init__.py subpackage1/ __init__.py moduleA.py moduleB.py moduleC.py moduleD.py
Hi, I have 20 strings, each of which will have same package structure except
i have a package structure that I want to match on. it can be
I have a maven project in eclipse with a folder structure are follows -
Say I have developed a game, and placed it in the package structure: com.dxmio.games.breakout

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.