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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:56:45+00:00 2026-05-18T10:56:45+00:00

I shall simplify the code slightly in the hopes that someone can shed some

  • 0

I shall simplify the code slightly in the hopes that someone can shed some light on this and maybe give me a more pythonic approach if what im doing is wrong.

Inside dbcontrollers.py

import autosettings
import aerialcontroller
import controller
import gobject
import gtk
import utils

# Create the settings object so we can call and edit settings easily
SETTINGS = autosettings.autoSettings()
CONTROLLERS = {}

class dBControllers(object):

    def __init__(self):

        # This works happily so nothing wrong in autosettings module
        print SETTING.last_port
        port_to_use = SETTINGS.last_port

if __name__ == "__main__":

    # Create an object that holds all the GTK stuff (when not simplified)
    dBControllers = dBControllers()
    aerialController = aerialcontroller.aerialController()

Inside aerialcontroller.py

class aerialController(object):

    def __init__(self):

        self.motor_number = str(SETTINGS.aerial_motor_number)
        CONTROLLERS[self.motor_number] = self

But when I run this, I get “NameError: global name ‘SETTINGS’ is not defined”.

I don’t really understand how this is supposed to work, sharing global variables accross modules. I assume this is not the correct way to do things like this, so can someone point me in the right direction.

Thank-you.

P.S. Simply code examples would be beneficial – still a relative newcomer to python.

  • 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-05-18T10:56:45+00:00Added an answer on May 18, 2026 at 10:56 am

    Python doesn’t have a way to share a name across modules. If there’s something you want access to from multiple modules, you declare it in a separate module (e.g. “settings”), and then import it wherever you want it.

    settings.py:

    SETTINGS = autosettings.autoSettings()
    CONTROLLERS = {}
    

    aerialcontroller.py

    from settings import SETTINGS, CONTROLLERS
    class aerialController(object):
    
        def __init__(self):
            self.motor_number = str(SETTINGS.aerial_motor_number)
            CONTROLLERS[self.motor_number] = self
    

    N.B. Doing from settings import SETTINGS will work as long as you only want to modify SETTINGS. If you want to completely replace it with a new set of settings (SETTINGS = ...) you need to do import settings, and refer to it as settings.SETTINGS.

    This is by design: if modules got variables from the script that imported them, it would be much harder to see where they came from when reading the code (and importing the module from somewhere else might not work). Doing it this way, you can always see where the variable came from within each file (well, almost always: please don’t overuse from <name> import *).

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

Sidebar

Related Questions

This is a idea for a security. Our employees shall have access to some
I have some Perl code that executes a shell script for multiple parameters, to
I have a canvas in Flex that shall be able only to be scrolled
For whatever reason, our company has a coding guideline that states: Each class shall
I have a small script that shall redirect to another page when return is
i have more than 100 coordinates (Latitude and Longitude), for that i want to
I think I shall reframe my question from Where should you use BlockingQueue Implementations
I am creating a small modal form that is used in Winforms application. It
I have a small JS function that does Ajax for me and another like
I've got a function that takes data and either returns the same data or

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.