0

Say I have a folder Dir with several files Funs_1, Funs_2 each of which contain several functions with unique names. Structure is as such:

project
│   foo.py
└───Dir
       Funs_1 >> some_function_1
       Funs_2 >> some_function_2

How can I call some_function_1 and some_function_2 from the project file foo.py using Dir.Funs_1.some_function_1 or something of that nature?

Yaakov Bressler
  • 9,056
  • 2
  • 45
  • 69
  • You have to import them. – juanpa.arrivillaga Jan 07 '20 at 17:08
  • 1
    In essence you need to first import the files from the directory `from Dir import Funs_1, Funs_2`, and then call the functions from the imported names: `Funs_1.some_function_1(*args, **kwargs)`, `Funs_2.some_function_2(*args, **kwargs)` – Ajax1234 Jan 07 '20 at 17:14

1 Answers1

1

In your case you can simply import the file from the directory and then access the functions:

from Dir import Funs_1, Funs_2
Funs_1.some_function_1()
Funs_2.some_function_2()

Alternatively:

import Dir.Funs_1, Dir.Funs_2
Dir.Funs_1.some_function_1()
Dir.Funs_2.some_function_2()
Ajax1234
  • 69,937
  • 8
  • 61
  • 102