this code is get the templates/blog1/page.html in b.py:
path = os.path.join(os.path.dirname(__file__), os.path.join("templates", "blog1/page.html"))
but i want to get the parent dir location:
aParent |--a | |---b.py | |---templates | |--------blog1 | |-------page.html |--templates |--------blog1 |-------page.html
and how to get the aParent location
this is right:
dirname=os.path.dirname path = os.path.join(dirname(dirname(__file__)), os.path.join("templates", "blog1/page.html"))
path = os.path.abspath(os.path.join(os.path.dirname(__file__),".."))
You can apply dirname repeatedly to climb higher:
dirname(dirname(file)). This can only go as far as the root package, however. If this is a problem, use
Use relative path with the
pathlib module in Python 3.4+:
from pathlib import Path Path(__file__).parent
You can use multiple calls to
parent to go further in the path:
As an alternative to specifying
parent twice, you can use:
The Apache Hadoop software library has come into it’s own. It is the basis for advanced distributed development for a host of companies, government institutions, and scientific research facilities. ...
If you can program, you are ready to grapple with Bayesian statistics. In this book, you'll learn how to solve statistical problems using Python code instead of math formulas, using discrete probabili...
The role of adaptation, learning and optimization are becoming increasingly essen- tial and intertwined. The capability of a system to adapt either through modification of its physiological structure ...
Introduction to Machine Learning with Python: A Guide for Data Scientists 1st Edition. Machine learning has become an integral part of many commercial applications and research projects, but this f...