Python analyzes job submission and python job submission
This is a very close task: analyzing job submission in python.
Requirements:
Compare the information of the student (extracted based on the file name) who handed in the assignment on the server with the student information in the score table, output the information (student ID and name) of all students who have not handed in the assignment, and output the information of the file name with incorrect naming format in the submitted assignment (for example, 1627406012_E03 ....).
Tip:
Tip:
1. You can obtain the information of all students who have handed in their homework Based on the Server File.
2. You can obtain information about all students in the course according to the table.
3. Compare the information in 1 and 2 to find the desired information.
Note: The incorrect file format should be taken into account when extracting the information of the task handed in by the server middle school student. Therefore, relevant processing should be done when extracting the information to avoid exceptions.
The following is a program (version of python3 ):
# Coding: UTF-8 import OS import xlrd "This function is used to obtain the content of files in the dir folder. dir cannot contain the Chinese name" "def getFilesInfo (dir ): fileNum = dir [len (dir)-2: len (dir)] # obtain the question number trueList = [] errorList = [] t = OS. walk (dir) for item in t: for name in item [2]: if len (name )! = 18: errorList. append (name) else: if name [13:15] = fileNum: trueList. append (name [0: 10]) else: errorList. append (name) return [trueList, errorList] # This function is used to read def readTableContent (fileName): date = xlrd. open_workbook (fileName) # sheet_name = date. sheet_names () [0] stuList = [] # store the student ID and name try: # Get the first table sh = date of the xls to be processed. sheet_by_index (0) failed T: print ("something wrong") for I in range (2, sh. nrows): id = sh. row_values (I) [1] name = sh. row_values (I) [2] student = (id, name); # The student id and name tuples stuList. append (student) return stuList address = "D: // my files/python homework corrections/grade 2016 lajiang homework 2016-10-25.xls" submitStuList = getFilesInfo ("D: \ E01 ") stuList = readTableContent (address) # list of student information stored notSubmitStudent = [] # information of students not submitting assignments for student in stuList: if student [0] not in submitStuList [0]: notSubmitStudent. append (student) print ("============================= people who have not handed in the job ==================== ") for student in notSubmitStudent: print (student [0], student [1]) print ("================================ file with incorrect format ======================== ") for error in submitStuList [1]: print (error)
For the above program, a table reading package xlrd is used. You need to download this package by yourself. In pycharm, download the package directly as follows:
1. First, perform the following operations:
2. Click "+" (because I downloaded the package in advance, the xlrd package is shown in the figure below ):
3. Enter the package name in the input box and search
4. Complete the installation:
For more information about the OS and xlrd used in the program, see relevant documents.
The following is a program of py2.7:
# Coding: UTF-8 import OS import xlrd import xlwt "This function is used to obtain the file content in the dir folder. the dir cannot contain the Chinese name" def getFilesInfo (dir ): fileNum = dir [len (dir)-2: len (dir)] # obtain the question number trueList = [] errorList = [] t = OS. walk (dir) for item in t: for name in item [2]: if len (name )! = 18: errorList. append (name) else: if name [13:15] = fileNum: trueList. append (name [0: 10]) else: errorList. append (name) return [trueList, errorList] # This function is used to read def readTableContent (fileName): date = xlrd. open_workbook (fileName) # sheet_name = date. sheet_names () [0] stuList = [] # store the student ID and name try: # Get the first table sh = date of the xls to be processed. sheet_by_index (0) failed T: print "problem" for I in range (2, sh. nrows): id = sh. row_values (I) [1]. encode ('utf-8') name = sh. row_values (I) [2] student = (id, name); # The student id and name tuples stuList. append (student) return stuList address = unicode ("D: // my files/python homework correction/grade 2016 lajiang class homework", 'utf-8 ') # convert the path of the Chinese name to submitStuList = getFilesInfo ("D: \ E01") stuList = readTableContent (address) # student information list notSubmitStudent = [] # student information not submitted for student in stuList: if student [0] not in submitStuList [0]: notSubmitStudent. append (student) print "==================== people who have not handed in their jobs ================" for student in notSubmitStudent: print student [0], student [1] print "===================== the format of the file is incorrect =================" for error in submitStuList [1]: print error
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.