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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:44:06+00:00 2026-05-24T09:44:06+00:00

DEFINE1 = 1 DEFINE2 = 2 DEFINE3 = 3 … DEFINE10 = 10 Let’s

  • 0
DEFINE1 = 1
DEFINE2 = 2
DEFINE3 = 3
...
DEFINE10 = 10

Let’s say one file has 10 global constants that I want to import into another file.

Instead of doing the following, is there any simpler way to import all the global constants without doing something like: from file_one.py import *. I don’t want it to import the entire file, just the global variables.

from file_one.py import DEFINE1, DEFINE2, DEFINE3, ..............
  • 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-24T09:44:07+00:00Added an answer on May 24, 2026 at 9:44 am

    First of all, I think it’s perfectly okay to create a lot of constants like you’re doing and put them all in a constants.py file and then do a from constants import * – I do this myself all the time. So long as all of my constants are defined in that file, I know exactly where to look when I need to figure out where SOME_CONSTANT came from.

    But I’ll assume for the moment that you have a module with a lot of constants and they all consist of upper-case letters, numbers, and underscores. At that point you can do something very hackish like

    import re, file_one
    for name,val in file_one.__dict__.items():
        if re.match("[A-Z0-9_]+", name):
            globals()[name] = val
    

    I would strongly advise against this sort of hackery, but this would make it possible to automatically import the constants you define without having to list them individually.

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

Sidebar

Related Questions

I've made a yaml file like below. Define1: &Define1 0: zero 1: one Define2:
I want to write preprocessor functions/arrays that are evaluated at compile time. For example,
I have 2 programs that share a header file. This header file defines a
I want to compile a project differently, according to a constant defined by #define,
I defined a record named log . I want to create an mnesia table
I have a small problem with a define. I want to assign it to
I need a function that takes the name of a symbol as a string
I'd like to implement an assert that prevents compilation, rather than failing at runtime,
I've been hacking on a program that itself creates simulation programs in C .
I want to alternate rowcolor in a GridView, using pure CSS, ie: I don't

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.