os.getcwd()
返回当前文件绝对路径
import os x = os.getcwd() print(x)
打印结果 G:deep-learning-for-image-processing-mastertensorflow_classification
os.path.join()
传入多个字符串类型,将其拼接
import os y = r"G:tensorflow_classification" z = "Test2_alexnet" n = "class_indices.json" print(os.path.join(y,z,n))
打印结果 G:tensorflow_classificationTest2_alexnetclass_indices.json
os.path.exist()
传入一个路径(字符串),判断其是否存在,返回一个布尔类型
import os y = r"G:tensorflow_classification" print(os.path.exists(y))
打印结果 False
os.makedir()
传入一个路径,在该路径下创建一个文件夹
import os
os.makedirs("save_weights")
自行实验
os.listdir()
传入一个绝对路径,以列表的形式返回该路径下所有文件的文件名
import os x = os.listdir(r"G:deep-learning-for-image-processing-mastertensorflow_classificationsave_weights") print(x)
打印结果 ['sun.jpg', '新建文件夹']



