检查可用盘符

  1. def get_disk_list():
  2. # This function will return a list which have accessible disks
  3. disk_list = []
  4. for c in string.ascii_uppercase:
  5. disk = c+':'
  6. if os.path.isdir(disk): # if the dir is exists, add it to the list
  7. disk_list.append(disk)
  8. return disk_list

遍历所有文件

  1. def walk_file(file):
  2. for root, dirs, files in os.walk(file):
  3. # root 表示当前正在访问的文件夹路径
  4. # dirs 表示该文件夹下的子目录名list
  5. # files 表示该文件夹下的文件list
  6. # 遍历文件
  7. for f in files:
  8. print(os.path.join(root, f))
  9. # 遍历所有的文件夹
  10. for d in dirs:
  11. print(os.path.join(root, d))
  12. def main(path):
  13. walk_file(path)
  14. # os.getcwd() 获取当前工作路径,可以作为参数传入

xls转换为xlsx

  1. import os # 导入系统包
  2. import win32com.client as win32 # 将Win32com导入为win32
  3. if __name__ == '__main__':
  4. fname = os.getcwd() + '\Test.xls' # 获取绝对地址文件名
  5. excel = win32.gencache.EnsureDispatch('Excel.Application') # 调用win32
  6. wb = excel.Workbooks.Open(fname) # 存为wb对象
  7. wb.SaveAs(fname + "x", FileFormat=51) # FileFormat = 51 is for .xlsx extension
  8. wb.Close() # FileFormat = 56 is for .xls extension
  9. excel.Application.Quit()

互相转换

  1. import win32com.client as win32 # 需安装pywin32
  2. import os.path
  3. import glob
  4. excel = win32.gencache.EnsureDispatch('Excel.Application')
  5. #简易使用方法
  6. #filename = r'E:\xlsx\1.xls'
  7. #wb = excel.Workbooks.Open(filename)
  8. #wb.SaveAs(filename+'x', FileFormat=51) #FileFormat=51 是 .xlsx 的扩展
  9. #wb.Close() #FileFormat=56 是 .xls 的扩展
  10. #excel.Application.Quit()
  11. def xls2xlsx(xls_path, xlsx_path):
  12. # xls_path参数为待转换的xls文件所在文件夹
  13. # xlsx_path参数为转换完成的xlsx文件保存文件夹
  14. # 当xlsx保存文件夹存在同名原xls时,会弹窗提示是否替换,建议保存至空文件夹
  15. path_list = glob.glob(xls_path + '\\*.xls') # 获取文件夹下所有xls
  16. for file in path_list:
  17. filename = os.path.basename(file).replace('.xls', '.xlsx') # 获取文件名
  18. wb = excel.Workbooks.Open(file)
  19. wb.SaveAs(xlsx_path + '\\' + filename, FileFormat=51) # xlsx为51
  20. wb.Close()
  21. excel.Application.Quit()
  22. print('xls2xlsx转换完成')
  23. def xlsx2xls(xlsx_path, xls_path):
  24. # xlsx_path参数为待转换的xlsx文件所在文件夹
  25. # xls_path参数为转换完成的xls文件保存文件夹
  26. # 当xls保存文件夹存在同名原xlsx时,会弹窗提示是否替换,建议保存至空文件夹
  27. path_list = glob.glob(xlsx_path + '\\*.xlsx') # 获取文件夹下所有xlsx
  28. for file in path_list:
  29. filename = os.path.basename(file).replace('.xlsx', '.xls') # 获取文件名
  30. wb = excel.Workbooks.Open(file)
  31. wb.SaveAs(xls_path + '\\' + filename, FileFormat=56) # xls为56
  32. wb.Close()
  33. excel.Application.Quit()
  34. print('xlsx2xls转换完成')
  35. if __name__ == '__main__':
  36. xls_path = r'E:\xlsx\xls'
  37. xlsx_path = r'E:\xlsx\xlsx'
  38. xls2xlsx(xls_path, xlsx_path)
  39. #xlsx2xls(xlsx_path, xls_path)

重命名

rename

  1. import os,sys
  2. def add_prefix_subfolders(path):
  3. mark = 'pre'
  4. old_names = os.listdir(path)
  5. for old_name in old_names:
  6. os.rename( os.path.join(path,old_name) , os.path.join(path,mark+old_name) )
  7. print(old_name,'has been renamed as ', mark+old_name)
  8. if __name__ == '__main__':
  9. path = os.getcwd()
  10. add_prefix_subfolders(path)

传入path 保护脚本模式

  1. import os,sys #导入模块
  2. def rename_subfolders(): #定义函数名称
  3. old_names = os.listdir( path ) #取路径下的文件名,生成列表
  4. for old_name in old_names: #遍历列表下的文件名
  5. if old_name!= sys.argv[0]: #代码本身文件路径,防止脚本文件放在path路径下时,被一起重命名
  6. new_name=old_name.replace('test-','test2-') #将原来名字里的‘test’替换为‘test2’
  7. os.rename(os.path.join(path,old_name),os.path.join(path,new_name)) #子文件夹重命名
  8. print (old_name,"has been renamed successfully! New name is: ",new_name) #输出提示

创建文件夹

  1. import os
  2. def mkdir(path):
  3. folder = os.path.exists(path)
  4. if not folder: #判断是否存在文件夹如果不存在则创建为文件夹
  5. os.makedirs(path) #makedirs 创建文件时如果路径不存在会创建这个路径
  6. print "--- new folder... ---"
  7. print "--- OK ---"
  8. else:
  9. print "--- There is this folder! ---"
  10. file = "G:\\xxoo\\test"
  11. mkdir(file) #调用函数

创立工作区

  1. import os
  2. work_space_path = os.getcwd() + '\DMS_WorkSpace' # Work Space Name
  3. def make_DMS_dir(path):
  4. folder = os.path.exists(path)
  5. if not folder: #判断是否存在文件夹如果不存在则创建为文件夹
  6. os.makedirs(path) #makedirs 创建文件时如果路径不存在会创建这个路径
  7. print "Work Space Has Been Created!"
  8. else:
  9. print "Work Space has already exists"
  10. make_DMS_dir(work_space_path) #调用函数

OS 操作

  1. os.listdir(dirname):列出dirname下的目录和文件
  2. os.getcwd():获得当前工作目录
  3. os.curdir:返回当前目录('.')
  4. os.chdir(dirname):改变工作目录到dirname
  5. os.path.isdir(name):判断name是不是一个目录,name不是目录就返回false
  6. os.path.isfile(name):判断name是不是一个文件,不存在name也返回false
  7. os.path.exists(name):判断是否存在文件或目录name
  8. os.path.getsize(name):获得文件大小,如果name是目录返回0L
  9. os.path.abspath(name):获得绝对路径
  10. os.path.normpath(path):规范path字符串形式
  11. os.path.split(name):分割文件名与目录(事实上,如果你完全使用目录,它也会将最后一个目录作为文件名而分离,同时它不会判断文件或目录是否存在)
  12. os.path.splitext():分离文件名与扩展名
  13. os.path.join(path,name):连接目录与文件名或目录
  14. os.path.basename(path):返回文件名
  15. os.path.dirname(path):返回文件路径
  16. os.remove(dir) #dir为要删除的文件夹或者文件路径
  17. os.rmdir(path) #path要删除的目录的路径。需要说明的是,使用os.rmdir删除的目录必须为空目录,否则函数出错。
  18. os.path.getmtime(name) #获取文件的修改时间
  19. os.stat(path).st_mtime#获取文件的修改时间
  20. os.stat(path).st_ctime #获取文件创建时间
  21. os.path.getctime(name)#获取文件的创建时间

时间戳操作

  1. #endcoding: utf-8
  2. # 获取文件的时间属性
  3. # 用到的知识
  4. # os.getcwd() 方法用于返回当前工作目录
  5. # os.path.getatime(file) 输出文件访问时间
  6. # os.path.getctime(file) 输出文件的创建时间
  7. # os.path.getmtime(file) 输出文件最近修改时间
  8. import time
  9. import os
  10. def fileTime(file):
  11. return [
  12. time.ctime(os.path.getatime(file)),
  13. time.ctime(os.path.getmtime(file)),
  14. time.ctime(os.path.getctime(file))
  15. ]
  16. times = fileTime(os.getcwd())
  17. print(times)
  18. print(type(times))

文件操作

  1. #文件、文件夹的移动、复制、删除、重命名
  2. #导入shutil模块和os模块
  3. import shutil,os
  4. #复制单个文件
  5. shutil.copy("C:\\a\\1.txt","C:\\b")
  6. #复制并重命名新文件
  7. shutil.copy("C:\\a\\2.txt","C:\\b\\121.txt")
  8. #复制整个目录(备份)
  9. shutil.copytree("C:\\a","C:\\b\\new_a")
  10. #删除文件
  11. os.unlink("C:\\b\\1.txt")
  12. os.unlink("C:\\b\\121.txt")
  13. #删除空文件夹
  14. try:
  15. os.rmdir("C:\\b\\new_a")
  16. except Exception as ex:
  17. print("错误信息:"+str(ex))#提示:错误信息,目录不是空的
  18. #删除文件夹及内容
  19. shutil.rmtree("C:\\b\\new_a")
  20. #移动文件
  21. shutil.move("C:\\a\\1.txt","C:\\b")
  22. #移动文件夹
  23. shutil.move("C:\\a\\c","C:\\b")
  24. #重命名文件
  25. shutil.move("C:\\a\\2.txt","C:\\a\\new2.txt")
  26. #重命名文件夹
  27. shutil.move("C:\\a\\d","C:\\a\\new_d")

工作区设计

Original
Logs
版本注释

长春大学课程表

  1. # -*- coding: utf-8 -*-
  2. # Filename:BasicCurriculumInfo
  3. import math
  4. class CourseUnit:
  5. __defaultWorkbook = 0
  6. __defaultWorksheet = 0
  7. __curriculumArea = 0
  8. __static_to_class_m = 0
  9. # if your code a tool func and don't want to be static, add this useless statement
  10. def __init__(self, workbook_obj):
  11. self.__defaultWorkbook = workbook_obj
  12. self.__defaultWorksheet = self.__defaultWorkbook.worksheets[0]
  13. self.__curriculumArea = self.__defaultWorksheet['B4:H9']
  14. # The ADT of B4:H9 consisted by tuple(tuple()) access by [][]
  15. def get_curriculums(self): # this is a test func
  16. return self.__curriculumArea
  17. def get_duration(self, week, num):
  18. week_list_all = []
  19. curriculum_string = self.__curriculumArea[num - 1][week - 1].value
  20. if curriculum_string == ' ':
  21. return -1
  22. if self.__find_all_subs('[周]', curriculum_string) != -1:
  23. index_list = self.__find_all_subs('[周]', curriculum_string)
  24. newline_list = []
  25. num_of_para = len(index_list)
  26. for i in index_list:
  27. newline_list.append(curriculum_string[0:i].rfind('\n'))
  28. week_str = []
  29. for i in range(0, num_of_para):
  30. week_str.append(curriculum_string[newline_list[i] + 1:index_list[i]])
  31. week_string = ""
  32. for subs in week_str:
  33. for chars in subs:
  34. week_string += chars
  35. week_string += ','
  36. week_string = week_string.replace(',', '@', 6)
  37. week_string = week_string.split('@')
  38. week_list = self.__curriculum_expansion(week_string)
  39. week_list_all.extend(week_list)
  40. if self.__find_all_subs('[双周]', curriculum_string) != -1:
  41. index_list = self.__find_all_subs('[双周]', curriculum_string)
  42. newline_list = []
  43. num_of_para = len(index_list)
  44. for i in index_list:
  45. newline_list.append(curriculum_string[0:i].rfind('\n'))
  46. week_str = []
  47. for i in range(0, num_of_para):
  48. week_str.append(curriculum_string[newline_list[i] + 1:index_list[i]])
  49. week_string = ""
  50. for subs in week_str:
  51. for chars in subs:
  52. week_string += chars
  53. week_string += ','
  54. week_string = week_string.replace(',', '@', 6)
  55. week_string = week_string.split('@')
  56. week_list = self.__curriculum_expansion(week_string)
  57. week_list_all.extend(week_list)
  58. if self.__find_all_subs('[单周]', curriculum_string) != -1:
  59. index_list = self.__find_all_subs('[单周]', curriculum_string)
  60. newline_list = []
  61. num_of_para = len(index_list)
  62. for i in index_list:
  63. newline_list.append(curriculum_string[0:i].rfind('\n'))
  64. week_str = []
  65. for i in range(0, num_of_para):
  66. week_str.append(curriculum_string[newline_list[i] + 1:index_list[i]])
  67. week_string = ""
  68. for subs in week_str:
  69. for chars in subs:
  70. week_string += chars
  71. week_string += ','
  72. week_string = week_string.replace(',', '@', 6)
  73. week_string = week_string.split('@')
  74. week_list = self.__curriculum_expansion(week_string)
  75. week_list_all.extend(week_list)
  76. week_list_all.sort()
  77. return week_list_all
  78. def __find_all_subs(self, sub, s):
  79. self.__static_to_class_m = 0
  80. index_list = []
  81. index = s.find(sub)
  82. while index != -1:
  83. index_list.append(index)
  84. index = s.find(sub, index + 1)
  85. if len(index_list) > 0:
  86. return index_list
  87. else:
  88. return -1
  89. def __str_to_int(self, o_str):
  90. self.__static_to_class_m = 0
  91. char_list = []
  92. for chars in o_str:
  93. char_list.append(chars)
  94. int_list = []
  95. for ints in char_list:
  96. int_list.append(int(ints) - int('0'))
  97. bit = len(int_list)
  98. local_iter = 0
  99. integer = 0
  100. while bit != 0:
  101. integer += int_list[local_iter] * math.pow(10, bit - 1)
  102. local_iter += 1
  103. bit -= 1
  104. return int(integer)
  105. def __curriculum_expansion(self, o_str_list):
  106. self.__static_to_class_m = 0
  107. u_list = []
  108. u_start = 0
  109. u_end = 0
  110. t_list = []
  111. for step_len in o_str_list:
  112. if step_len == '':
  113. continue
  114. if '-' in step_len:
  115. u_list = step_len.split('-')
  116. u_start = u_list[0]
  117. u_end = u_list[1]
  118. u_start = self.__str_to_int(u_start)
  119. u_end = self.__str_to_int(u_end)
  120. for i in range(u_start, u_end + 1):
  121. t_list.append(i)
  122. elif '-' not in step_len:
  123. t_list.append(self.__str_to_int(step_len))
  124. t_list.sort()
  125. return t_list
  126. def __reconnect_lists(self, o_list, t_list):
  127. self.__static_to_class_m = 0
  128. o_list = o_list.expand(t_list)
  129. for chapter in o_list:
  130. if chapter.find('*') > 10:
  131. o_list.append('*')
  132. chapter.reiter_count()
  133. elif chapter.thread_max() < 50:
  134. t_list.reinsert(chapter.iter.en())
  1. # -*- coding: utf-8 -*-
  2. # Filename:BasicCurriculumInfo
  3. import openpyxl as vpa
  4. import re
  5. class StudentSheetInfo:
  6. __defaultWorkbook = 0
  7. __defaultWorksheet = 0
  8. __basicTitle = 0
  9. __infoTitle = 0
  10. def __init__(self, workbook_obj):
  11. self.__defaultWorkbook = workbook_obj
  12. self.__defaultWorksheet = self.__defaultWorkbook.worksheets[0]
  13. self.__basicTitle = self.__defaultWorksheet['A1']
  14. self.__infoTitle = self.__defaultWorksheet['A2']
  15. def get_class_sheet_name(self):
  16. name_position = []
  17. for i in range(0, len(self.__basicTitle.value)):
  18. if self.__basicTitle.value[i] == ' ':
  19. name_position.append(i)
  20. return self.__basicTitle.value[name_position[0]+1:name_position[1]]
  21. # the format of str: "CollegeName Name Title"
  22. def get_class_sheet_school_year(self):
  23. school_year_position = re.search('学年学期:', self.__infoTitle.value).span()
  24. for i in range(school_year_position[1], len(self.__infoTitle.value)):
  25. if self.__infoTitle.value[i] == ' ':
  26. end_mark = i
  27. break
  28. return self.__infoTitle.value[school_year_position[1]:end_mark]
  29. # the format of str: "学年学期:YYYY-YYYY-I ..."
  30. def get_class_sheet_class(self):
  31. school_year_position = re.search('班级:', self.__infoTitle.value).span()
  32. for i in range(school_year_position[1], len(self.__infoTitle.value)):
  33. if self.__infoTitle.value[i] == ' ':
  34. end_mark = i
  35. break
  36. return self.__infoTitle.value[school_year_position[1]:end_mark]
  37. # the format of str: "班级:MajorYYNUM ..."
  38. def get_class_sheet_major(self):
  39. school_year_position = re.search('所属班级:', self.__infoTitle.value).span()
  40. for i in range(school_year_position[1], len(self.__infoTitle.value)):
  41. if self.__infoTitle.value[i] == ' ':
  42. end_mark = i
  43. break
  44. return self.__infoTitle.value[school_year_position[1]:end_mark]
  45. # the format of str: "所属班级:MajorYYNUM ..."
  46. def get_class_sheet_update_time(self):
  47. return self.__infoTitle.value[-10:]

新更新

  1. # -*- coding: utf-8 -*-
  2. # Filename:BasicCurriculumInfo
  3. import math
  4. class CourseUnit:
  5. __defaultWorkbook = 0
  6. __defaultWorksheet = 0
  7. __curriculumArea = 0
  8. __static_to_class_m = 0
  9. # if your code a tool func and don't want to be static, add this useless statement
  10. def __init__(self, workbook_obj):
  11. self.__defaultWorkbook = workbook_obj
  12. self.__defaultWorksheet = self.__defaultWorkbook.worksheets[0]
  13. self.__curriculumArea = self.__defaultWorksheet['B4:H9']
  14. # The ADT of B4:H9 consisted by tuple(tuple()) access by [][]
  15. def get_curriculums(self): # this is a test function
  16. return self.__curriculumArea
  17. def get_duration(self, week, num):
  18. week_list_all = []
  19. curriculum_string = self.__curriculumArea[num - 1][week - 1].value
  20. if curriculum_string == ' ':
  21. return -1
  22. if self.__find_all_subs('[周]', curriculum_string) != -1:
  23. index_list = self.__find_all_subs('[周]', curriculum_string)
  24. newline_list = []
  25. num_of_para = len(index_list)
  26. for i in index_list:
  27. newline_list.append(curriculum_string[0:i].rfind('\n'))
  28. week_str = []
  29. for i in range(0, num_of_para):
  30. week_str.append(curriculum_string[newline_list[i] + 1:index_list[i]])
  31. week_string = ""
  32. for subs in week_str:
  33. for chars in subs:
  34. week_string += chars
  35. week_string += ','
  36. week_string = week_string.replace(',', '@', 20 + 1)
  37. week_string = week_string.split('@')
  38. week_list = self.__curriculum_expansion(week_string)
  39. week_list_all.extend(week_list)
  40. if self.__find_all_subs('[双周]', curriculum_string) != -1:
  41. index_list = self.__find_all_subs('[双周]', curriculum_string)
  42. newline_list = []
  43. num_of_para = len(index_list)
  44. for i in index_list:
  45. newline_list.append(curriculum_string[0:i].rfind('\n'))
  46. week_str = []
  47. for i in range(0, num_of_para):
  48. week_str.append(curriculum_string[newline_list[i] + 1:index_list[i]])
  49. week_string = ""
  50. for subs in week_str:
  51. for chars in subs:
  52. week_string += chars
  53. week_string += ','
  54. week_string = week_string.replace(',', '@', 6)
  55. week_string = week_string.split('@')
  56. week_list = self.__curriculum_expansion(week_string)
  57. week_list_all.extend(week_list)
  58. if self.__find_all_subs('[单周]', curriculum_string) != -1:
  59. index_list = self.__find_all_subs('[单周]', curriculum_string)
  60. newline_list = []
  61. num_of_para = len(index_list)
  62. for i in index_list:
  63. newline_list.append(curriculum_string[0:i].rfind('\n'))
  64. week_str = []
  65. for i in range(0, num_of_para):
  66. week_str.append(curriculum_string[newline_list[i] + 1:index_list[i]])
  67. week_string = ""
  68. for subs in week_str:
  69. for chars in subs:
  70. week_string += chars
  71. week_string += ','
  72. week_string = week_string.replace(',', '@', 6)
  73. week_string = week_string.split('@')
  74. week_list = self.__curriculum_expansion(week_string)
  75. week_list_all.extend(week_list)
  76. week_list_all.sort()
  77. return week_list_all
  78. def __find_all_subs(self, sub, s): # find all substring in string
  79. self.__static_to_class_m = 0
  80. index_list = []
  81. index = s.find(sub)
  82. while index != -1:
  83. index_list.append(index)
  84. index = s.find(sub, index + 1)
  85. if len(index_list) > 0:
  86. return index_list # return location index
  87. else:
  88. return -1 # return -1 if nothing have found
  89. def __str_to_int(self, o_str): # convert a string type number to int
  90. self.__static_to_class_m = 0
  91. char_list = []
  92. for chars in o_str:
  93. char_list.append(chars)
  94. int_list = []
  95. for ints in char_list:
  96. int_list.append(int(ints) - int('0'))
  97. bit = len(int_list)
  98. local_iter = 0
  99. integer = 0
  100. while bit != 0:
  101. integer += int_list[local_iter] * math.pow(10, bit - 1)
  102. local_iter += 1
  103. bit -= 1
  104. return int(integer)
  105. def __curriculum_expansion(self, o_str_list): # get a string with ',' and expand it
  106. self.__static_to_class_m = 0
  107. t_list = []
  108. for step_len in o_str_list:
  109. if step_len == '':
  110. continue
  111. if '-' in step_len:
  112. u_list = step_len.split('-')
  113. u_start = u_list[0]
  114. u_end = u_list[1]
  115. u_start = self.__str_to_int(u_start)
  116. u_end = self.__str_to_int(u_end)
  117. for i in range(u_start, u_end + 1):
  118. t_list.append(i)
  119. elif '-' not in step_len:
  120. t_list.append(self.__str_to_int(step_len))
  121. t_list.sort()
  122. return t_list
  123. def get_curriculum_layout(self): # convert list to a binary number (int)
  124. layout = []
  125. for week in range(1, 7 + 1): # 7 days a week and a bound
  126. for chapter in range(1, 6 + 1): # 6 lesson a day and a bound
  127. layout.append(self.list_to_binary(self.get_duration(week, chapter)))
  128. return layout
  129. @staticmethod
  130. def list_to_binary(o_list):
  131. m_binary = 0
  132. if o_list == -1: # runtime datatype double check, (Customized)
  133. return -1
  134. for it in o_list:
  135. m_binary += 2 ** it
  136. return m_binary
  137. @staticmethod
  138. def binary_to_list(o_bin):
  139. const_bit = 0b1
  140. m_list = []
  141. for it in range(0, 20):
  142. ret = o_bin & const_bit # get last bit
  143. if ret == 1:
  144. m_list.append(it)
  145. o_bin = o_bin >> 1
  146. return m_list
  147. """
  148. Excel cannot convert a list data type to a table data type.
  149. However, the list is not repeated, so I can use binary
  150. distribution to represent the contents of the list.
  151. for example i have a list which is [2, 3, 5]
  152. i cannot put it into excel cells, but i can transfer
  153. this list into a number which is 0b101100
  154. 0 b 1 0 1 1 0 0
  155. ^ ^ ^
  156. 5 3 2
  157. and this number is 44 (int)
  158. """
  1. # -*- coding: utf-8 -*-
  2. # Filename:BasicCurriculumInfo
  3. """
  4. class provides basic information of curriculum table
  5. most of method may not used in actual practice
  6. the variable 'end_mark' is local variable, ignore
  7. some warnings below:
  8. "Local variable 'end_mark' might be referenced before assignment"
  9. DO NOT ADD GLOBAL STATEMENTS
  10. """
  11. import re
  12. class StudentSheetInfo:
  13. __defaultWorkbook = 0
  14. __defaultWorksheet = 0
  15. __basicTitle = 0
  16. __infoTitle = 0
  17. def __init__(self, workbook_obj):
  18. self.__defaultWorkbook = workbook_obj
  19. self.__defaultWorksheet = self.__defaultWorkbook.worksheets[0]
  20. self.__basicTitle = self.__defaultWorksheet['A1']
  21. self.__infoTitle = self.__defaultWorksheet['A2']
  22. def get_class_sheet_name(self):
  23. name_position = []
  24. for i in range(0, len(self.__basicTitle.value)):
  25. if self.__basicTitle.value[i] == ' ':
  26. name_position.append(i)
  27. return self.__basicTitle.value[name_position[0]+1:name_position[1]]
  28. # the format of str: "CollegeName Name Title"
  29. def get_class_sheet_school_year(self):
  30. school_year_position = re.search('学年学期:', self.__infoTitle.value).span()
  31. for i in range(school_year_position[1], len(self.__infoTitle.value)):
  32. if self.__infoTitle.value[i] == ' ':
  33. end_mark = i
  34. break
  35. return self.__infoTitle.value[school_year_position[1]:end_mark]
  36. # the format of str: "学年学期:YYYY-YYYY-I ..."
  37. def get_class_sheet_class(self):
  38. school_year_position = re.search('班级:', self.__infoTitle.value).span()
  39. for i in range(school_year_position[1], len(self.__infoTitle.value)):
  40. if self.__infoTitle.value[i] == ' ':
  41. end_mark = i
  42. break
  43. return self.__infoTitle.value[school_year_position[1]:end_mark]
  44. # the format of str: "班级:MajorYYNUM ..."
  45. def get_class_sheet_major(self):
  46. school_year_position = re.search('所属班级:', self.__infoTitle.value).span()
  47. for i in range(school_year_position[1], len(self.__infoTitle.value)):
  48. if self.__infoTitle.value[i] == ' ':
  49. end_mark = i
  50. break
  51. return self.__infoTitle.value[school_year_position[1]:end_mark]
  52. # the format of str: "所属班级:MajorYYNUM ..."
  53. def get_class_sheet_update_time(self):
  54. return self.__infoTitle.value[-10:]