'Import and convert module into qtdesign

I would like to integrate the python modules (in the algo/ folder) into the main program that uses an interface_ui is created by QT designer.

This is my folder structure.

├── algo/
│   └── main_algo.py
│   └── a.py
│   └── b.py
│   └── read_data.py
│   └── data/
│       └── data.bin
└── main.py
        └── interface_ui.py

Note that the main_algo.py will import a.py, b.py, and read_data.py (function to read data.bin)

So, I have two solutions:

  1. I have created a button in the interface and executed the function main_algo.py each time I push the button

    exec(open("path/main_algo.py.py").read())

  2. I would convert all the modules inside the algo/ folder into the function and call back the function in the main.py whenever I want.

    import sys
    sys.path.insert(1,"path_to_algo/")
    from a import x,y
    from b import z
    import read_data
    

Please tell me the advantages of each solutions and how can we do the second solution.

Thank you very much



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source