Search
 
SCRIPT & CODE EXAMPLE
 

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

Comment

python import from parent directory

exec(open(<filename.py>).read())
Comment

import file from parent directory python

import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# import ../db.py
import db
Comment

get file parent directory python

from pathlib import Path
path = Path("/here/your/path/file.txt")
print(path.parent.absolute())
Comment

import from parent directory python

from ... import nib
Comment

import from parent directory in python setup

from setuptools import setup, find_packages

    setup(name='myproject', version='1.0', packages=find_packages())
Comment

PREVIOUS NEXT
Code Example
Python :: matplotlib boxplot colors 
Python :: path to create a text file in python 
Python :: save model tensorflow 
Python :: convert numpy array to cv2 image 
Python :: python check if array is subset of another 
Python :: color python 
Python :: np one hot encoding 
Python :: separate a string in python 
Python :: graph 3d python 
Python :: print typeof in python 
Python :: python from float to decimal 
Python :: python regex 
Python :: publisher python ros 
Python :: python - change the bin size of an histogram+ 
Python :: django logout page 
Python :: beautiful soup 4 
Python :: socket io python 
Python :: python replace by dictionary 
Python :: python string: iterate string 
Python :: python hide input 
Python :: np arange 
Python :: schedule computer shutdown python 
Python :: pandas append csv file 
Python :: remove ,drop,effacer, dataframe,python 
Python :: change tkinter app icon 
Python :: append value to numpy array 
Python :: python numpy array size of n 
Python :: string to list python 
Python :: how to find an element in a list python 
Python :: making a virtual environment python 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =