1

This is my folder structure:

-Test
      -Folder1
            -a.py
      -Folder2
            -test.py
      -b.py

where a.py:

def a():
    print('a works!')

and b.py:

def b():
    print('b works!')

How do I run functions a() and b() from test.py?

I have tried from Folder1.a import a, from .Folder1.a import a and many other variations.

user572780
  • 257
  • 3
  • 10
  • See [This Stack-Overflow Post](https://stackoverflow.com/questions/4383571/importing-files-from-different-folder) for information. – NoahBlaut Jun 03 '21 at 22:25
  • Does [this post](https://stackoverflow.com/questions/4383571/importing-files-from-different-folder) answer your question? – Ivan Litteri Jun 03 '21 at 22:30
  • Unless `test.py` and `b.py` are together part of a single package, it's generally not a good sign if you need to reference a module that sits at a higher level than the module you're referencing it from. If everything starts to reference everything, you should consider the structure of your program and how you break it up. You *can* reference `b` from `test`, but you should consider if you *should*. – Grismar Jun 03 '21 at 22:31
  • @Grismar Well, I am actually looking to reference `a` from `test` and was just curious about `b`. – user572780 Jun 03 '21 at 22:33
  • You don’t import files from directories; you import *modules*, which you arrange to be on `sys.path`. You can install your modules in a “global” path entry, or you can add a specific entry for your modules. These are the answer to each of the hundreds of questions on this topic. – Davis Herring Jun 03 '21 at 23:02

0 Answers0