Answers for "python import upper directory"

2

python import file from parent directory

import os,sys,inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir) 

import mymodule

OR 

import os, sys

sys.path.insert(1, os.getcwd()) 
import variables
Posted by: Guest on June-04-2020
1

how to determine python project parent dir

import os,sys,inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir) 

import mymodule

OR 

import os, sys

sys.path.insert(1, os.getcwd()) 
import variables
Posted by: Guest on December-30-2020
0

python import upper directory

import sys
sys.path.append('../../../')
import your_file
Posted by: Guest on October-20-2021

Code answers related to "python import upper directory"

Python Answers by Framework

Browse Popular Code Answers by Language