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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:42:33+00:00 2026-06-06T13:42:33+00:00

What is the standard way of declaring configuration variables for your program at the

  • 0

What is the standard way of declaring configuration variables for your program at the top of a python script? These are used throughout the program in multiple classes and functions. Is the best way:

  1. To create a mixed dictionary with the configuration options, and pass these to any classes that need them. Downside: this requires passing extra attributes. For example:

    config = {'parseTags': {'title','font','p'},    
        'name': 'steve',                
        'logFrequencies': 10,               
        'print_rate': False  
        }
    

     

    newCustomObject = CustomClass(config)
    customfunction(config)
    print 'hi',config['name']
    
  2. Create global variables at the beginning of the file and call those throughout the program. Downside: ruins the encapsulation of the classes.

  3. Something else.

What is the most pythonic way of doing this?

  • 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-06T13:42:34+00:00Added an answer on June 6, 2026 at 1:42 pm

    For constants used in a single file (module), I usually just declare global variables at the top. This does not lose encapsulation in any meaningful way (it’s no different from putting those constants in a base class that every class inherits from).

    The django config system provides a nice way to create shared constants: you create a module, and the config system creates a read-only object from it, exposing the members of the module.

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

Sidebar

Related Questions

The standard way of declaring an enum in C++ seems to be: enum <identifier>
What is the standard way to determine that these 2 similar Uris are actually
Well ! I got confused about the way of declaring variables & implementing its
Possible Duplicate: Declaring Multiple Variables in JavaScript I was setting some variables in jQuery
Is there a standard way to associate version string with a Python package in
What is the standard way of using mysql in python. I define standard as
Is there a standard way that the tools used to generate the API documents
I love declaring variables on the stack, especially when using the standard container. Each
Is there a proper/standard way? <a href=# onclick=function();>Link</a> vs <script> $(document).ready(function(){ $('#link1').click(function(){ ... });
What is the standard way of incorporating helper/utility functions in Obj-C classes? I.e. General

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.