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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:56:41+00:00 2026-05-21T15:56:41+00:00

e.g. A configuration file can have CFLAGS = xyz CXXFLAGS = xyz OR CXXFLAGS

  • 0

e.g. A configuration file can have

CFLAGS = "xyz"
CXXFLAGS = "xyz"

OR

CXXFLAGS = "xyz"
CFLAGS = "xyz"

Best implementation I could think of would be to just split the argument and feed the left side into a switch

for line in file
    x = line.split("=")
    switch(x[0])
        case CFLAGS
             do cflags
        case CXXFLAGS
             do cxxflags

But how do people who have way more experience than me do it? I know theres probably some open source programs who do this but I wouldn’t even know where to look in their source for this.
I program mainly in python and C so implementations/pseudocode/whattolookup in both would be preferred although other languages are fine also.

Thanks in advance.

P.S. try to avoid saying any form of re, regex, regexp, regular expressions, or any derivative thereof in your answers unless its unavoidable :P.

  • 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-21T15:56:42+00:00Added an answer on May 21, 2026 at 3:56 pm

    As Eli Bendersky says, in Python you should just use the provided ConfigParser.

    If you insist on doing it yourself, his method of storing the configuration as a dictionary is one I recommend. Another way is to map the options to functions which process the values and do something with them:

    # Map the options to functions to handle them.
    handlers = {
        'CFLAGS': some_function,
        'CXXFLAGS': other_function,
    }
    
    # Loop through each option.
    for line in configuration:
        # Get the option and value.
        option, value = line.split('=')
        option = option.strip().upper()
        value = value.strip()
    
        # Try to find a handler and process the option.
        handler = handlers.get(option)
        if handler:
            handler(option, value)
        else:
            raise Exception('Unknown option.')
    

    Obviously, the handler functions must be able to accept the option and value parameters you’re passing it.

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

Sidebar

Related Questions

I have a configuration file where a developer can specify a text color by
I have a script which can overwrite values in a configuration file using options,
I have a configuration file that i would like to update with classic asp.
Like ini file, I basically want to have an easy-to-edit configuration file that can
Can I have two AuthUserFile directives in an apache2/sites-enabled/000-default configuration file? <Location /repo/trac> AuthType
Suppose I have a configuration file that can be in one of two format
Is it possible to create a custom configuration file (other than app.config) that can
To my knowledge Nginx can only password protect directories from within the configuration file(s).
can somebody paste me deploy.rb file with configuration for LOCAL MACHINE ? Whenever i
I have an ANT configuration file which is becoming complicated, and now I'm stuck

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.