-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork08_文件读写.py
46 lines (35 loc) · 1.29 KB
/
work08_文件读写.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
# @Time : 2022/4/1 9:37
# @Author : jinjie
import datetime
import dateutil
import time
# 1. 编写一个copy函数,接收2个参数(源路径、目标路径),可以实现文件的拷贝
def copy(source_path,target_path):
fread = open(source_path,'rb')
fwrite = open(target_path,'wb')
while True:
data = fread.read(1024)
if not data:
break
fwrite.write(data)
# print("复制成功")
fread.close()
fwrite.close()
copy(r"D:\\caiji_system_report",r"D:\\caiji_system_report_copy")
# 2. 编写一个函数,计算当前,距离10.1国庆,还差几天
def calculate_national():
now_time = time.localtime(time.time())
date_year_now = datetime.datetime.now().year
date_month_now = datetime.datetime.now().month
if date_month_now < 10:
date_str = str(date_year_now) + "-10-01"
else:
date_str = str(date_year_now+1) + "-10-01"
date_national = time.strptime(date_str,"%Y-%m-%d")
date1 = datetime.datetime(date_national[0],date_national[1],date_national[2])
date2 = datetime.datetime(now_time[0],now_time[1],now_time[2])
diff_days = (date1-date2).days
return diff_days
if __name__ == '__main__':
print(f"还有{calculate_national()}天是下一个国庆节")