python getcwd函数如何与其他路径操作函数配合使用
Python的os模块提供了一系列用于路径操作的函数,可以与getcwd函数配合使用来获得当前工作目录并进行其他路径操作。下面是一些经常使用的路径操作函数及其与getcwd函数的结合使用示例:
import os
cwd = os.getcwd()
new_path = os.path.join(cwd, "new_folder")
print(new_path)
import os
cwd = os.getcwd()
abs_path = os.path.abspath(cwd)
print(abs_path)
import os
cwd = os.getcwd()
files = os.listdir(cwd)
print(files)
import os
cwd = os.getcwd()
new_folder = os.path.join(cwd, "new_folder")
os.makedirs(new_folder)
import os
cwd = os.getcwd()
exists = os.path.exists(cwd)
print(exists)
通过结合getcwd函数和其他路径操作函数,可以方便地获得当前工作目录并进行其他路径操作。
tiktok粉丝购买:https://www.smmfensi.com/
TOP