Tuesday 19 February 2019

python - How do I import package/module from a directory above

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 scriopts 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 either get a ValueError:Attempted relative import beyond top-level package or function_folder is not a module

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...