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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:26:36+00:00 2026-06-14T09:26:36+00:00

I started using Python few days back and I think I have a very

  • 0

I started using Python few days back and I think I have a very basic question where I am stuck. Maybe I am not doing it correctly in Python so wanted some advice from the experts:

I have a config.cfg & a class test in one package lib as follows:

myProj/lib/pkg1/config.cfg

[api_config]
url = https://someapi.com/v1/
username=sumitk

myProj/lib/pkg1/test.py

class test(object):

    def __init__(self, **kwargs):

        config = ConfigParser.ConfigParser()
        config.read('config.cfg')
        print config.get('api_config', 'username') 
          #just printing here but will be using this as a class variable

    def some other foos()..

Now I want to create an object of test in some other module in a different package

myProj/example/useTest.py

from lib.pkg1.test import test

def temp(a, b, c):
    var = test()

def main():
    temp("","","")

if __name__ == '__main__':
    main()

Running useTest.py is giving me error:

...
print config.get('api_config', 'username')
File "C:\Python27\lib\ConfigParser.py", line 607, in get
     raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'api_config'

Now if I place thie useTest.py in the same package it runs perfectly fine:

myProj/lib/pkg1/useTest.py
myProj/lib/pkg1/test.py
myProj/lib/pkg1/config.cfg

I guess there is some very basic package access concept in Python that I am not aware of or is there something I am doing wrong here?

  • 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-14T09:26:38+00:00Added an answer on June 14, 2026 at 9:26 am

    The issue here is that you have a different working directory depending on which module is your main script. You can check the working directory by adding the following lines to the top of each script:

    import os
    print os.getcwd()
    

    Because you just provide 'config.cfg' as your file name, it will attempt to find that file inside of the working directory.

    To fix this, give an absolute path to your config file.

    You should be able to figure out the absolute path with the following method since you know that config.cfg and test.py are in the same directory:

    # inside of test.py
    import os
    config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               'config.cfg')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A few days back, I started using new OpenCV-Python interface, cv2 . My question
I just started using Python and I have a question about idle vs terminal.
I just started using/learning Python and have some questions. I have a text file
I'm a Python beginner and have just started using packages. When you're calling a
I have started using Python for web development recently, it's kinda cool; I have
I have been having some trouble with matplotlib since I started using python. When
I started using django framework just a few days ago and i desperately need
sorry for the stupid question ... just started using python (but I love it).
I just started out using python and went straight to django. I have set
When I started learning Python, I created a few applications just using functions and

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.