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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:25:34+00:00 2026-06-10T11:25:34+00:00

how do you inherit globals from other .py file? Example: globals.py test = ‘testValue’

  • 0

how do you inherit globals from other .py file?

Example:
globals.py

test = 'testValue'

index.py

from globals import *

def setGlobals():
    global test
    test = 'new Value' # Setting new value to project global  

setGlobals()

help.py

from globals import *
print test # Should print out 'new Value', but it prints 'testValue'

I wish to have one file full of constants and global variables that is set by another file and also used by other files. In this example I set new value to global variable test in index.py and wish to use new value in help.py. Am I using the wrong approach for python? Thank you.

EDIT:
Sequence of events is same as exampled, e.g. first I import, set new value and then try printing out newly set value from another 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-10T11:25:36+00:00Added an answer on June 10, 2026 at 11:25 am

    In Python modules are objects. When you do an import, you are copying and possibly renaming the attributes of one module into the current module. However, this only copies the value (or more specifically copies the reference by value). If the imported module is later changed, your copy won’t be. One possible approach is to try defining your globals in the second module as properties, but I’m not sure if that even works.

    However, what you are trying to do is terrible design anyway. You need to rethink why you want to have global values being accessed and modified everywhere. Try refactoring your code and replacing anything left with dependency injection. For example, replace your globals module with a configuration object that you can pass around to whoever needs it.

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

Sidebar

Related Questions

I'm using boost singletons (from serialization). For example, there are some classes which inherit
How to inherit from the windows explorer (Desktop, thing with help of which we
I'm wanting to inherit from System.Web.Security.MembershipProvider - but I require more data than just
If I inherit from a class that is serializable but I specifically do not
I need inherit events and properties. For example, I need to move a picture
I have 2 classes both inherit from the same interface. i want sometimes to
I have a class Application that my global.asax inherits from. The class has this
I'm working on some classes that get part of their configuration from global variables,
I created an ApplicationController.cs that all other Controllers inherit. I'm trying to use this
I'm trying to inherit QSqlTableModel to make data im my table display in way

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.