You can use the os.path
module to find the root directory of a given file in Python. Here's an example:
main.py208 chars10 lines
This code will print the absolute path of the root directory containing the file. The os.path.join()
function is used to join the file's parent directory (identified using the os.pardir
constant) with the file's name. The os.path.abspath()
function is then used to get the absolute path of the resulting directory.
gistlibby LogSnag