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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:56:46+00:00 2026-05-17T06:56:46+00:00

I am using a large list of variables inside some definitions and classes (mainly

  • 0

I am using a large list of variables inside some definitions and classes (mainly because I want to be able to use the code-folding feature of pydev). Is there any constructor I can use on a definition or class to make its variables automatically considered globals?


This is an example of what I did after following some of the recommendations provided on the comments:

From:

img_globe       = os.path.join(set_img_dir, 'img_globe.png')
img_help        = os.path.join(set_img_dir, 'img_help.png')
img_exit        = os.path.join(set_img_dir, 'img_exit.png')
img_open        = os.path.join(set_img_dir, 'img_open.png')
img_tutorial    = os.path.join(set_img_dir, 'img_tutorial.png')
img_save        = os.path.join(set_img_dir, 'img_save.png')
img_site        = os.path.join(set_img_dir, 'img_site.png')

… (long, long list)

To:

varies = {}
dirList=os.listdir(set_img_dir)
for fname in dirList: 
    varies[fname.split(".")[0]] = os.path.join(set_img_dir, fname)
  • 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-17T06:56:46+00:00Added an answer on May 17, 2026 at 6:56 am

    Although you should not do this and the solution you are looking for is not as simple as you might think, here is a very simple example of how you might take the local variables from within a function and make them global:

    def make_locals_globals():
        """This is just bad"""
        foo = 1
        bar = 2
    
        locals_dict = locals()
        globals_dict = globals()
    
        print 'Locals:', locals_dict
    
        for varname, varval in locals_dict.items():
            print 'Setting global: %s=%s' % (varname, varval)
            globals_dict[varname] = varval
    
    if __name__ == '__main__':
        make_locals_globals()
    
        print '\nGlobals:'
        print 'foo=', foo
        print 'bar=', bar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a large open-source control and I can't seem to find the code
When copying large files using shutil.copy() , you get no indication of how the
Anybody out there using BGL for large production servers? How many node does your
Is anyone out there using Drupal for large scale, business critical enterprise applications? Does
I have a large application (~50 modules) using a structure similar to the following:
As I am using for-loops on large multi-dim arrays, any saving on the for-loop
I am creating a large table dynamically using Javascript. I have realised the time
We are using Maven for a large build process (> 100 modules). We have
I've just started using the MVP pattern in the large ASP.NET application that I'm
I believe strongly in using unit-tests as part of building large multi-platform applications. We

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.