0

I have a following directory structure:

                                parentDirectory
                                       |
                   -----------------------------------------
                  |                                         |
                 Task                                    Configs
                   - pythonFile1.py                         - Config1.py
                                                            - Config2.py

The Configuration files have few configuration constants defined inside a class.

Now, I want to import the configuration files from Configs directory into the python file under Tasks directory and make use of constants defined inside the class in each config file.

I had tried with adding(after reading through few answers) -

sys.path.insert(0,'/home/MyName/parentDirectory/Tasks')

inside the config files.

Since I am new to python, I don't know to what extent I am correct in adding the above lines.

Please help!

Goblin
  • 43
  • 2
  • 3
  • 8
  • It may be interesting to look at the [*package* chapter](https://docs.python.org/3/tutorial/modules.html#packages) in Python tutorial – Serge Ballesta Oct 09 '14 at 06:31

1 Answers1

1

I think you got it backward: if you want your "Tasks" to be able to import your "Configs", you need to add code to the Tasks to insert the Configs path into sys.path.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • Adding the line to "Tasks" throws an error saying- Importerror: No module named Config1 – Goblin Oct 09 '14 at 06:10
  • OK. Now imagine what I am thinking when you say "it throws an error." How can I help you? What other information must I need? – John Zwinck Oct 09 '14 at 06:11