Python提取官方节假日文件中的放假日期
发布时间
阅读量:
阅读量
import pandas as pd
import os
import re
from datetime import timedelta
# 将 “节假日安排的txt” 文件放在当前目录下
this_path = os.getcwd() # 获取当前的工作路径
file_name = os.path.join(this_path, "节假日安排.txt") # 获取节假日安排的绝对路径
holiday_list = list() # 存放 放假日期
with open(file_name,'r', encoding="utf-8") as file: #打开文件
title = file.readline()
holiday_year = re.search(r".*(\d{4})年", title).group(1) # 节假日年份
file_data = file.readlines() #读取所有行
for row in file_data:
if re.match(r"\w、", row):
date_group = re.search(r"(.*?)(\d{1,2}月\d{1,2
全部评论 (0)
还没有任何评论哟~
