文件读写

【待更】
txt文件

with open('10k_links.txt', 'w') as f:
  # …… 提取file_name 
  f.write(f'https://www.sec.gov/Archives/{file_name}\n')

批量读取

# 批量读取文件夹下的多个txt文件名
import os
from pprint import pprint

fdir = "./data/Prospectus_Zh/" # . means current working directory
filenames = os.listdir(fdir) # list all file names in the specified directory
pprint(filenames)

pkl格式文件(list等格式文件的读写)

import pickle
# 将列表保存为二进制文件
with open("xxx.pkl", "wb") as file:
    pickle.dump(allNewsText, file)

# 从文件中加载列表
with open("xxx.pkl", "rb") as file:
    loaded_list = pickle.load(file)
posted @ 2023-03-28 12:02  Rae的笔记本  阅读(22)  评论(0)    收藏  举报