1

I am new to python. My searches did not give the results I am after.

I have a simple python script in folder_base/settings.py.

My other script in folder_next/settings.py would like to behave as folder_base/settings.py. One way is to use symbolic links but I avoid this method. I want any function called from folder_next/settings.py, they call the one in the base folder and return the same value.

I was even trying methods such as

from ..folder_base/settings.py import func1 as _func1

def func1():
    return _func1()

which did not work for me. Any solution is appreciated but a solution that automatically forward the entire script is even better.

P.S. The linked question does not solve my problem. Adding another path just creates a name collision.

Can some one please remove the irrelevant duplication link?

twist
  • 11
  • 2
  • 1
    Possible duplicate of [Importing files from different folder](https://stackoverflow.com/questions/4383571/importing-files-from-different-folder) – James May 12 '19 at 01:48
  • Can you give a better picture of your file hierarchy? It's possible that your relative imports aren't working here because the parent directory of both `folder_base` and `folder_next` doesn't have a `__init__.py` file. – Green Cloak Guy May 12 '19 at 01:49
  • @James it does not solve the name collision. – twist May 12 '19 at 01:49
  • @GreenCloakGuy, Just two folder and a few independent settings file in each. `C++` calls them, read them and behaves as configured. – twist May 12 '19 at 01:52
  • @twist what is the main entry point into your project? does your project contain any other modules, folders, or files? when you run your project is `folder_next/settings.py` the first file you run? more info on how you run your project is helpful to provide an answer. – chickity china chinese chicken May 12 '19 at 06:19
  • I have an idea to accomplish what you want to do but it requires adding another script in the parent folder above `folder_next` and `folder_base`, if you put `from folder_next import settings` in the parent folder script, then you can call `from folder_base.settings import func1` in `folder_next/settings.py`. – chickity china chinese chicken May 12 '19 at 06:44

0 Answers0