Answers for "import from upper directory python"

33

python get filename from path

import os
print(os.path.basename(your_path))
Posted by: Guest on February-28-2020
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

Code answers related to "import from upper directory python"

Python Answers by Framework

Browse Popular Code Answers by Language