Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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

Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #import #file #parent #directory
ADD COMMENT
Topic
Name
1+8 =