import os dirct = 'D:/data' dirList=[] fileList=[] files=os.listdir(dirct) #文件夹下所有目录的列表 print('files:',files) for f in files: if os.path.isdir(dirct + '/'+f): #这里是绝对路径,该句判断目录是否是文件夹 dirList.append(f) elif os.path.isfile(dirct + '/'+f):#这里是绝对路径,该句判断目录是
这个功能是以lib的形式提供的,配置写到home下的.pythonrc文件中, 并设置好环境变量让python启动时执行初始化: # ~/.pythonrc # enable syntax completion # add the next line to your ~/.bashrc # export PYTHONSTARTUP=~/.pythonrc try: import readline except ImportError: print("Module readline not ava
from PIL import Image import os def rea(path, pdf_name): file_list = os.listdir(path) pic_name = [] im_list = [] for x in file_list: if "jpg" in x or 'png' in x or 'jpeg' in x: pic_name.append(x) pic_name.sort() new_pic = [] for x in pic_name: i
使用spark-submit提交local任务时,会输出很多Info信息: ------------------------------------------- Time: ms ------------------------------------------- // :: INFO scheduler.JobScheduler: Finished job streaming job ms. ms // :: INFO scheduler.JobScheduler: Total delay
1 文件与IO 1.1读写文本数据 读写各种不同的文本数据,如ASCII,UTF-8,UTF-9编码等. 使用带有rt模式的open()函数读取文本文件. 例如: with open('db', 'rt') as f: data = f.read() print(data) with open('db', 'rt') as f: for line in f: print(line.strip('\n')) 使用带有wt的open()函数写入一个文本文件,如果之前文件内容存在则清除并覆盖掉. 例如