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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:43:07+00:00 2026-05-27T22:43:07+00:00

Using the ConfigParser module I am attempting to read in a configuration file so

  • 0

Using the ConfigParser module I am attempting to read in a configuration file so I can safely allow users to edit settings for an application and share these configurations between scripts.
This has been working perfectly for the main script. However there is a secondary script that is called and it reads the same configuration file in the same location but returns an error that the location cannot be found.
Both scripts are located within the same directory, application/bin/
The configuration file is located in application/conf/ To reference the config file successfully in the main script I use the following code which works perfectly.

config = ConfigParser.ConfigParser()
config.readfp(open('../conf/settings.conf'))

When the secondary script executes with the same code it reports that the location does not exist? I used the logger module and got it to log sys.path[0] which correctly returned the same bin folder as the main script. Is there possibly something simple I am missing here?

Also any troubleshooting tips for problems like these are welcome.

  • 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-27T22:43:08+00:00Added an answer on May 27, 2026 at 10:43 pm

    You can prefer to use dirname and __file__:

    from os.path import dirname, join
    config = ConfigParser.ConfigParser()
    config_fn = join(dirname(__file__), '..', 'conf', 'settings.conf')
    config.read(config_fn)
    

    Depending how you’re launching the app (python bin/app.py, or python app.py), the ‘..’ will be incorrect. By starting from the directory of the .py file, you’ll always be able to construct the path from the .py to the .conf using that method.

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

Sidebar

Related Questions

Using ConfigParser I can read value of key easily as shown in the example
I can use the ConfigParser module in python to create ini-files using the methods
I am using ConfigParser to save simple settings to a .ini file, and one
I have a python class which reads a config file using ConfigParser: Config file:
Ok i am planning on using the configparser module for creation of a few
Which is better for creating a settings file for Python programs, the built-in module
I have a config.cfg which I parse using the python-module ConfigParser. In one section
I'm using ConfigParser for configuring my application, and now I want to make it
I'm using Python 3.2 and the configparser module, and running into some problems. I
In my project we use a config file that's parsed with the configparser module.

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.