0

I am building a fairly complex python app with various scripts. I am planning on sorting these scripts into subfolders so I can then access the functions from a main file. For example having a function called main inside a file called test.py inside a subfolder called test. How would I call the function?

I have tried using

from test import main

However I get a ModuleNotFoundError error.

Thanks in advance for the help.

BarryBBenson
  • 71
  • 1
  • 6

1 Answers1

0

As mentioned here, to import files from subfolders in python, use the '.' to signify a subdirectory.

  • In your example, the import would be

from test.test import main

  • The general syntax for such an import would be the following:

from [subfolderName].[fileName] import [functionName]

  • To import all functions from file, the syntax would be:

import [subfolderName].[fileName]

Polydynamical
  • 242
  • 3
  • 18