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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:38:39+00:00 2026-06-16T20:38:39+00:00

StackOverflow, Below is the first few lines of my script: from ConfigParser import SafeConfigParser

  • 0

StackOverflow,

Below is the first few lines of my script:

from ConfigParser import SafeConfigParser
from docopt import docopt
import core as scrappy

ARGS = docopt(__doc__, version=scrappy.__version__)
if not ARGS['PATH']:
    ARGS['PATH'] = './'

# load config file
CFG = SafeConfigParser()
if not CFG.read(ARGS['--cfg']):  # call to CFG.read also loads file if it exists
    raise IOError('Configuration file not found.')

The configuration file I’m trying to read is in the same directory as the above script. By default, docopt sets the path to this file to ./file.conf (I have tested this with file.conf with identical results).

The last line of the script is always called, suggesting that the file can’t be found. I confirmed this by printing the output of os.getcwd, which revealed that the script’s execution directory is whichever directory the terminal was pointing to.

What gives?

What can I do to point to the configuration file?

  • 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-16T20:38:40+00:00Added an answer on June 16, 2026 at 8:38 pm

    Use __file__ predefined module attribute. Like this:

    module_dir = os.path.dirname(__file__)
    CFG = SafeConfigParser()
    cfg_full_path = os.path.join(module_dir, ARGS['--cfg'])
    if not CFG.read(cfg_full_path): 
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I found the solution, see below My first post on StackOverFlow. However I
I use StackOverflow for the first time, so please be friendly and understanding. Few
I've found this question on StackOverflow Adding div below images in colorbox But it
Having a array like below var arrNames = [Stackoverflow,StackExchange,Webmaster,Programmers]; how should a template look
I read this question in stackoverflow. The excerpt answer provided by bbum is below:
This is my first question at stackoverflow :-). However, I've started to Android programming
First question on stackoverflow :) Hope I won't embarrass myself... I have a javascript
This is my first post on stackoverflow so hopefully I don't sound too incompetent.
I am new to Python and this is my first time asking a stackOverflow
first, please see the blog as the link showed below: http://blogs.nitobi.com/joe/2008/10/17/phonegap-now-for-android/comment-page-1/#comment-12918 the author made

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.