-1
MyFolder/
        function_folder/
                    __init__.py
                    function.py
                          def some_func():
                              return 'i am func'
                    creds.py
                          class creds(elf)
                               self.user=[]
                               self.pw=[]
        test_folder/
                    test.py
        prod_folder/
                    live.py

We're trying to organize the folders such that we separate a folder for python functions and testing scripts and live scripts for automation.

How do you import function.py from live.py?

i've tried the following but none seem to work.

from .function import some_func
from ..function import some_func
from function_folder.function import *

I get the following error:

ValueError: Attempted relative import beyond top-level package or function_folder is not a module
Xiddoc
  • 3,369
  • 3
  • 11
  • 37
Kel
  • 51
  • 6

1 Answers1

1

This should work:

import sys
sys.path.append('path_to_MyFolder/function_folder')
import function
Xiddoc
  • 3,369
  • 3
  • 11
  • 37