标签:pat path color print txt dir get 拼接 port
获取当前目录
import os print os.getcwd() print os.path.abspath(os.path.dirname(__file__))
获取上级目录
import os print ‘***获取上级目录***‘ print os.path.abspath(os.path.dirname(os.path.dirname(__file__))) print os.path.abspath(os.path.dirname(os.getcwd())) print os.path.abspath(os.path.join(os.getcwd(), ".."))
获取上上级目录
import os print os.path.abspath(os.path.join(os.getcwd(), "../.."))
拼接文件路径
path = os.path.join(base_dir, ‘123.txt‘)
标签:pat path color print txt dir get 拼接 port
原文地址:https://www.cnblogs.com/RebeccaG/p/11727583.html