python insert parent directory into sys path for import file purpose

Solutions on MaxInterview for python insert parent directory into sys path for import file purpose by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "python insert parent directory into sys path for import file purpose"
Alyshialynn
29 Jan 2019
1import sys
2from os.path import dirname, abspath
3sys.path.insert(0, dirname(dirname(abspath(__file__))))
4
5path1 = dirname(abspath(__file__))  # current folder
6path2 = dirname(path1)  # parent folder
7
8print(path1)
9print(path2)
10