1

Preface: I've already seen this post. Please link other posts if this question has already been asked.

I'm calling a function from the imported module using the module.function() approach from the linked response above. However, the specific function I'm calling calls another function from the same module that was imported. How do you call a function that requires a call to another function inside of it? Here's an example to illustrate:

file1.py

def func_one(graphResultsPath,x,y,path):
    spec = importlib.util.spec_from_file_location('graphResults',graphResultsPath)
    graphResults = importlib.util.module_from_spec(spec)
    sys.modules[spec.name] = graphResults
    spec.loader.exec_module(graphResults)

    graphResults.create_plot(x,y,path)

graphResults.py

def create_plot(x,y,path):
    fig1 = plt.figure(num=1)
    plt.plot(x,y)
    plt.savefig(path)
    add_fig_to_pptx(path)

def add_fig_to_pptx(path):
    ...
John Herwig
  • 39
  • 1
  • 8
  • is it a question ? looks like https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly example to me ? – pippo1980 Feb 03 '22 at 22:17
  • Are you saying to just import both functions using the lazy importer? – John Herwig Feb 03 '22 at 22:29
  • 1
    I am saying I can't figure out what are you asking for, maybe I am not good enough to understand it, hope somebody better will answer, I am bookmarking/follow this question – pippo1980 Feb 03 '22 at 22:37
  • Thank you. I edited the post to add my specific problem. – John Herwig Feb 03 '22 at 23:03
  • 1
    What doesn’t work about what you have written already? – Davis Herring Feb 04 '22 at 05:48
  • @DavisHerring currently nothing happens because the create_plot function is unable to access the add_fig_to_pptx function – John Herwig Feb 08 '22 at 18:27
  • @JohnHerwig: "nothing" isn't a sensible possibility. Are you saying that it gets a `NameError`? – Davis Herring Feb 08 '22 at 19:26
  • not sure, it was getting called as the target of a thread from the threading library. So, I didn't receive any std output. Removing the call to the add_fig_to_pptx function and putting the add_fig_to_pptx function's lines of code inside create_plot's function was a quick solution for now. – John Herwig Feb 09 '22 at 07:28
  • what happens if you put all the functions of graphResults.py into a class and the use the same approach ---> graphResults.main.create_plot(x,y,path) ? – pippo1980 Feb 11 '22 at 11:58

0 Answers0