常用的小功能,收集目录下的图片,并将图片转成base64对象
具体代码如下:
#!/usr/bin/python3 #coding:utf-8 import os import base64 def file_list(path): files = [] d = os.walk(path) for parent, dirnames, filenames in d: for filename in filenames: if filename.endswith('jpg'): files.append(os.path.join(parent, filename)) else: continue return files if __name__ == "__main__": files = file_list(r"D:\\picture") img_bs64_list = [] for i in files: with open(i, 'rb') as f: _object = f.read() img_bs64_object = base64.b64encode(_object) img_bs64_list.append(img_bs64_object)