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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:44:40+00:00 2026-06-06T05:44:40+00:00

Three module exists. Cfg, Main and Component Cfg.py value = 0 Component.py import Cfg

  • 0

Three module exists. Cfg, Main and Component

Cfg.py

value = 0

Component.py

import Cfg

class index:
    def GET(self):
        return Cfg.value

Main.py

from Test import Cfg
import Component

urls = ('/', 'Component.index')

if __name__ == '__main__':

    Cfg.value = 1
    app = web.application(urls, globals())
    app.run()

Get method of Component.Index returns 0, but i’m expecting 1. What did i miss?

Edit #1

first modification main.py to test :

from test import Cfg
import Component
import test

if __name__ == '__main__':
    importedCfg = id(Cfg)
    cfgInComponent = id(Component.Cfg)
    cfgInTest = id(test.Cfg)

    print importedCfg, cfgInComponent, cfgInTest
    print importedCfg == cfgInComponent == cfgInTest

Result :

36202928 36203088 36202928
False

Second modification in main.py :

import Cfg
import Component

if __name__ == '__main__':
    importedCfg = id(Cfg)
    cfgInComponent = id(Component.Cfg)
    # cfgInTest = id(test.Cfg)

    print importedCfg, cfgInComponent
    print importedCfg == cfgInComponent 

36858160 36858160 True

if you do not want to create multiple instance you should follow the second way.

  • 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-06T05:44:42+00:00Added an answer on June 6, 2026 at 5:44 am

    Compare the result of:

    from Test import Cfg
    import Component
    
    if __name__ == '__main__':
        assert id(Cfg) == id(Component.Cfg)
    

    and

    import Cfg
    import Component
    
    if __name__ == '__main__':
        assert id(Cfg) == id(Component.Cfg)
    

    this means that doing a “from module” import creates different instances of Cfg. (I wasn’t aware of this either).

    This behavior is present in Python 2.7 and Python 3.2 (Python 2.6 wasn’t tested).

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

Sidebar

Related Questions

Given the following: class User; attr_accessor :roles; end module RegisteredUser def default_context Submission end
I have a Maven build with three modules. Module A exports a jar. Module
Is there any module in Orchard CMS that I can install to get a
From everything I've read on using Perl modules, the basic usage is: Module file
I know there exists a module (rpy and rpy2) to convert R code to
I'm in calendar hell, and I'm hoping there exists a Python module out there
I created a module and there exists a default controller inside that. Now I
in my drupal module code i check if a path exists but the condition
What I did Let's say my module was called some_module. Without disabling from the
I'm wondering if there exists a python module that would allow me to do

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.