File tree Expand file tree Collapse file tree 10 files changed +1900
-1500
lines changed Expand file tree Collapse file tree 10 files changed +1900
-1500
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 70
70
7 . [ 文件批量压缩] ( 文件批量压缩.md )
71
71
8 . [ 文件读写操作] ( 文件读写操作.md )
72
72
9 . [ 字符串32位加密] ( 字符串32位加密.md )
73
+ 10 . [ 寻找前10大的文件] ( 找出前10大的文件.md )
73
74
74
75
75
76
#### 七、字符串、正则和爬虫
83
84
8 . [ 字符串32位加密] ( 字符串32位加密.md )
84
85
9 . [ 反转字符串] ( 反转字符串1.md )
85
86
10 . [ 分词并保存结果] ( 分词并保存结果.md )
87
+ 11 . [ 求字符串的字节长度] ( 求字符串的字节长度.md )
86
88
87
89
#### 八、绘图
88
90
Original file line number Diff line number Diff line change
1
+ ``` python
2
+ from datetime import date, datetime
3
+ import calendar
4
+
5
+
6
+ def print_mydate (mydate ):
7
+ print (f ' 输入的日期: { mydate} \n ' )
8
+
9
+ year_calendar_str = calendar.calendar(mydate.year)
10
+ print (f " { mydate.year} 年的日历图: { year_calendar_str} \n " )
11
+
12
+ is_leap = calendar.isleap(mydate.year)
13
+ print_leap_str = " %s 年是闰年" if is_leap else " %s 年不是闰年\n "
14
+ print (print_leap_str % mydate.year)
15
+
16
+ month_calendar_str = calendar.month(mydate.year, mydate.month)
17
+ print (f " { mydate.year} 年- { mydate.month} 月的日历图: { month_calendar_str} \n " )
18
+
19
+ weekday, days = calendar.monthrange(mydate.year, mydate.month)
20
+ print (f ' { mydate.year} 年- { mydate.month} 月的第一天是那一周的第 { weekday} 天 \n ' )
21
+ print (f ' { mydate.year} 年- { mydate.month} 月共有 { days} 天 \n ' )
22
+
23
+ month_first_day = date(mydate.year, mydate.month, 1 )
24
+ print (f " 当月第一天: { month_first_day} \n " )
25
+
26
+ month_last_day = date(mydate.year, mydate.month, days)
27
+ print (f " 当月最后一天: { month_last_day} \n " )
28
+
29
+
30
+ print_mydate(date.today())
31
+
32
+
33
+ ```
Original file line number Diff line number Diff line change @@ -9,3 +9,4 @@ def str_byte_len(mystr):
9
9
10
10
str_byte_len(' i love python' ) # 13(个字节)
11
11
str_byte_len(' 字符' ) # 6(个字节)
12
+ ```
Original file line number Diff line number Diff line change @@ -13,18 +13,18 @@ def convert(input_file):
13
13
print (f'begin to convert { filename } ...' )
14
14
process = api .convert ({
15
15
'inputformat' : 'md' ,
16
- 'outputformat' : 'rst ' ,
16
+ 'outputformat' : 'pdf ' ,
17
17
'input' : 'upload' ,
18
- 'file' : open ('./md2/ {}' .format (input_file ), 'rb' )
18
+ 'file' : open ('./{}' .format (input_file ), 'rb' )
19
19
})
20
20
process .wait () # wait until conversion finished
21
21
# download output file
22
22
23
23
process .download (
24
- "./rst/ tmp/{}.rst " .format (filename ))
24
+ "./tmp/{}.pdf " .format (filename ))
25
25
print (f"convert { filename } success" )
26
26
27
27
28
- for input_file in os .listdir ('./md2 ' ):
28
+ for input_file in os .listdir ('.' ):
29
29
convert (input_file )
30
- time .sleep (1 )
30
+ # time.sleep(1)
Original file line number Diff line number Diff line change
1
+ from datetime import date , datetime
2
+ from time import localtime , strftime , strptime
3
+
4
+
5
+ today_date = date .today ()
6
+ print (today_date ) # 2019-12-22
7
+
8
+ today_time = datetime .today ()
9
+ print (today_time ) # 2019-12-22 18:02:33.398894
10
+
11
+ local_time = localtime ()
12
+ print (strftime ("%Y-%m-%d %H:%M:%S" , local_time )) # 转化为定制的格式
13
+
14
+ # parse str time to struct time
15
+ struct_time = strptime ('2019-12-22 10:10:08' , "%Y-%m-%d %H:%M:%S" )
16
+ print (strftime ("%m-%d-%Y %H:%M:%S" , struct_time )) # 转化为定制的格式
Original file line number Diff line number Diff line change
1
+ from datetime import date , datetime
2
+ import calendar
3
+
4
+
5
+ def print_mydate (mydate ):
6
+ print (f'输入的日期:{ mydate } \n ' )
7
+
8
+ year_calendar_str = calendar .calendar (mydate .year )
9
+ print (f"{ mydate .year } 年的日历图:{ year_calendar_str } \n " )
10
+
11
+ is_leap = calendar .isleap (mydate .year )
12
+ print_leap_str = "%s年是闰年" if is_leap else "%s年不是闰年\n "
13
+ print (print_leap_str % mydate .year )
14
+
15
+ month_calendar_str = calendar .month (mydate .year , mydate .month )
16
+ print (f"{ mydate .year } 年-{ mydate .month } 月的日历图:{ month_calendar_str } \n " )
17
+
18
+ weekday , days = calendar .monthrange (mydate .year , mydate .month )
19
+ print (f'{ mydate .year } 年-{ mydate .month } 月的第一天是那一周的第{ weekday } 天\n ' )
20
+ print (f'{ mydate .year } 年-{ mydate .month } 月共有{ days } 天\n ' )
21
+
22
+ month_first_day = date (mydate .year , mydate .month , 1 )
23
+ print (f"当月第一天:{ month_first_day } \n " )
24
+
25
+ month_last_day = date (mydate .year , mydate .month , days )
26
+ print (f"当月最后一天:{ month_last_day } \n " )
27
+
28
+
29
+ print_mydate (date .today ())
Original file line number Diff line number Diff line change
1
+ # 获取目录下文件的修改时间
2
+ import os
3
+ from datetime import datetime
4
+ print (f"当前时间:{ datetime .now ().strftime ('%Y-%m-%d %H:%M:%S' )} " )
5
+
6
+
7
+ def get_modify_datetime (indir ):
8
+ for root , _ , files in os .walk (indir ): # 循环D:\works目录和子目录
9
+ for file in files :
10
+ absfile = os .path .join (root , file )
11
+ modtime = datetime .fromtimestamp (os .path .getmtime (absfile ))
12
+ now = datetime .now ()
13
+ difftime = now - modtime
14
+ if difftime .days < 20 : # 条件筛选超过指定时间的文件
15
+ print (f"""{ absfile }
16
+ 修改时间[{ modtime .strftime ('%Y-%m-%d %H:%M:%S' )} ]
17
+ 距今[{ difftime .days :3d} 天{ difftime .seconds // 3600 :2d} 时{ difftime .seconds % 3600 // 60 :2d} ]"""
18
+ ) # 打印相关信息
19
+
20
+
21
+ get_modify_datetime ('./data' )
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+
4
+ def xls_to_xlsx (work_dir ):
5
+ """
6
+ 传递当前目录,原来后缀名,新的后缀名后,批量重命名后缀
7
+ """
8
+ old_ext , new_ext = '.xls' , '.xlsx'
9
+ for filename in os .listdir (work_dir ):
10
+ # 获取得到文件后缀
11
+ split_file = os .path .splitext (filename )
12
+ file_ext = split_file [1 ]
13
+ # 定位后缀名为old_ext 的文件
14
+ if old_ext == file_ext :
15
+ # 修改后文件的完整名称
16
+ newfile = split_file [0 ] + new_ext
17
+ # 实现重命名操作
18
+ os .rename (
19
+ os .path .join (work_dir , filename ),
20
+ os .path .join (work_dir , newfile )
21
+ )
22
+ print ("完成重命名" )
23
+ print (os .listdir (work_dir ))
24
+
25
+
26
+ xls_to_xlsx ('./data' )
You can’t perform that action at this time.
0 commit comments