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

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

PREVIOUS NEXT
Code Example
Python :: time in regression expression python 
Python :: anaconda 
Python :: binary python 
Python :: python convert list of lists to array 
Python :: python close gile 
Python :: postgresql backup using python 
Python :: create pandas dataframe 
Python :: check status code urllib open 
Python :: pytest logcli to write to file 
Python :: wxpython icon 
Python :: sort dictionary by key 
Python :: string in list py 
Python :: run multiple test cases pytest 
Python :: distinct query in django queryset 
Python :: tkinter canvas text size 
Python :: read pickle file 
Python :: python sum 
Python :: jupyter notebook GET 500 
Python :: read an excel file 
Python :: python bufferedreader 
Python :: muliline comment in pyhton 
Python :: flask api 
Python :: panda python 
Python :: python pandas how to select range of data 
Python :: why a Python Arithmetic Operators used 
Python :: how to make tkinter look better 
Python :: merge two columns name in one header pandas 
Python :: how to download from youtube in discord.py 
Python :: django create view 
Python :: python string formatting 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =