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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:28:31+00:00 2026-05-27T17:28:31+00:00

I am parsing a config file I would like to get only the values

  • 0

I am parsing a config file I would like to get only the values which are file paths in the file

for example the config file has

apache.access =  /var/log/apache2/access.log
apache.errors = /var/log/apache2/errors.log

I would like to get only ‘/var/log/apache2/access.log’ and ‘/var/log/apache2/errors.log’ from the

COMMENT_CHAR = '#'
OPTION_CHAR =  '='



def parse_config(filename):
    options = {}
    f = open(filename)
    for line in f:
        if COMMENT_CHAR in line:
           line, comment = line.split(COMMENT_CHAR, 1)
        if OPTION_CHAR in line:
            option, value = line.split(OPTION_CHAR, 1)
            option = option.strip()
            value = value.strip()
            options[option] = value
    f.close()
    return options 

I tried this but it gives all the options and values in the file

apache.access : /var/log/apache2/access.log

apache.errors : /var/log/apache2/errors.log

  • 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-27T17:28:31+00:00Added an answer on May 27, 2026 at 5:28 pm

    First you have to define, what is a file path (1. does it have to exist? 2. does it have to be creatable in an existing directory? 3. anything else?). This tests whether the given string is a path pointing to an existing dir/file:

    import os
    
    # ...
    
    [v for v in options.itervalues() if os.path.exists(v)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing the App.config file of a project. This config file has been loaded
I'm successfully parsing a cisco config file, and grabbing the sections of config between
When parsing an xml file in android, I'm doing like this: try { InputStream
I was using a certain method for parsing my app.config file. Then I was
I am trying to have my source control block in my ccnet.config file access
I would like to override the use of the standard app.config by passing a
I'm parsing a binary file format. It encodes an integer using four bytes in
I've create a custom configuration section in my web.config file for my 3.5 web
I want to get an array from a yaml file inside one of my
I'm trying to reference another object I've defined in a Spring config file from

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.