os.path.abspath()

os.path.abspath() 是 Python 中用于获取绝对路径的函数。它接受一个参数,即要转换为绝对路径的相对路径,并返回该相对路径的绝对路径。

示例:

import os

current_directory = os.getcwd()
print(current_directory)
# '/home/user/project'

relative_path = 'file.txt'
absolute_path = os.path.abspath(relative_path)
print(absolute_path)
# '/home/user/project/fi