python 如何在不知道的情况下获取相对文件路径。在此示例中,Python代码,HTML文件。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 如何在不知道的情况下获取相对文件路径。在此示例中,Python代码,HTML文件。相关的知识,希望对你有一定的参考价值。

# open new HTML file
# first, get the relative file path
script_path = os.path.abspath(__file__) # /path/to/dir/thisFile.py
script_dir = os.path.split(script_path)[0] # /path/to/dir/
rel_path = "Queries_New.html"
abs_file_path = os.path.join(script_dir, rel_path)
url = 'file:///' + abs_file_path
webbrowser.open(url, new=2)  # open in new tab

以上是关于python 如何在不知道的情况下获取相对文件路径。在此示例中,Python代码,HTML文件。的主要内容,如果未能解决你的问题,请参考以下文章