Ошибка «вне индекса» возникает из-за того, что указанный разделитель отличается от разделителя в данных.
На веб-сайте я обнаружил, что данные разделены символом «|». Программа использует ';' в качестве разделителя (в функции split ()).
Вот рабочий код с обновленным разделителем:
# File name: CourseInformation.py
import urllib.request
def instructors(department):
url = "http://cs1110.cs.virginia.edu/files/louslist/" + department
courses = urllib.request.urlopen(url)
professors = []
for course in courses:
if not course.decode("UTF-8").split("|")[4] in professors:
professors.append(course.decode("UTF-8").split("|")[4])
return sorted(professors)
def class_search(dept_name, has_seats_available=True, level=None, not_before=None, not_after=None):
arr = []
lists = []
url = "http://cs1110.cs.virginia.edu/files/louslist/" + dept_name
courses = urllib.request.urlopen(url)
for line in courses:
arr.append([j for j in line.decode("utf-8").rstrip('n').split('|')])
for find_course in arr:
if has_seats_available:
if int(find_course[15]) >= int(find_course[16]):
continue
if not level == None:
if find_course[1][0] != str(level)[0]:
continue
if not not_before is None:
if int(find_course[12]) < not_before:
continue
if not not_after == None:
if int(find_course[12]) > not_after:
continue
lists.append(find_course)
return lists
print(instructors("CS"))
print(class_search("CS"))
Вывод:
python CourseInformation.py
['Aaron Bloomfield', 'Abdeltawab Hendawi', 'Ahmed Ibrahim', 'Alfred Weaver', 'Andrew Grimshaw', 'Baishakhi Ray', 'Cameron Whitehouse', 'Charles Reiss', 'Collin/Cyrus', 'Connelly Barnes', 'Craig Dill', 'David Edwards', 'David Edwards+1', 'David Evans', 'Dimitrios Diochnos', 'Gabriel Robins', 'Haiying Shen', 'Homa Alemzadeh', 'Hongning Wang', 'Jack Davidson', 'James Cohoon', 'John Stankovic', 'Kai-Wei Chang', 'Katherine Holcomb', 'Kevin Angstadt', 'Kevin Sullivan', 'Kong-Cheng Wong', 'Lu Feng', 'Luther Tychonievich', 'Mark Floryan', 'Mark Sherriff', 'Marty Humphrey', 'Mary Smith', 'Mohammad Mahmoody Ghidary', 'Nada Basit', 'Samira Khan', 'Thomas Hall', 'Thomas Horton', 'Thomas Pinckney', 'Upsorn Praphamontripong', 'Vicente Ordonez-Roman']
[['CS', '1010', '001', 'Introduction to Information Technology', 'Craig Dill', 'Lecture', '3', 'true', 'false', 'true', 'false', 'false', '1530', '1645', 'Olsson Hall 120', '99', '100\n'], ['CS', '1110', '001', 'Introduction to Programming', 'Luther Tychonievich', 'Lecture', '3', 'true', 'false', 'true', 'false', 'true', '1400', '1450', 'Chemistry Bldg 402', '329', '350\n'], ['CS', '1110', '002', 'Introduction to Programming', 'Upsorn Praphamontripong', 'Lecture', '3', 'true', 'false', 'true', 'false', 'true', '1100', '1150', 'Wilson Hall 301', '181', '200\n'], ['CS', '1110', '106', 'Introduction to Programming', 'Luther Tychonievich', 'Laboratory', '0', 'false', 'false', 'false', 'true', 'false', '1830', '1945', 'Olsson Hall 001', '43', '46\n'], ['CS', '1110', '109', 'Introduction to Programming', 'Luther Tychonievich', 'Laboratory', '0', 'false', 'false', 'false', 'true', 'false', '1700', '1815', 'Mechanical Engr Bldg 213', '47', '48\n'], ['CS', '1110', '110', 'Introduction to Programming', 'Luther Tychonievich', 'Laboratory', '0', 'false', 'false', 'false', 'true', 'false', '1830', '1945', 'Mechanical Engr Bldg 213', '47', '48\n'], ['CS', '1113', '001', 'Introduction to Programming', 'Ahmed Ibrahim', 'Lecture', '3', 'true', 'false', 'true', 'false', 'true', '1100', '1150', 'Thornton Hall E316', '31', '80\n'], ['CS', '1501', '001', 'Special Topics in Computer Science', 'Mark Floryan', 'Lecture', '1', 'false', 'true', 'false', 'false', 'false', '1700', '1750', 'Thornton Hall E304', '27', '30\n'], ['CS', '1501', '002', 'Special Topics in Computer Science', 'Mark Floryan', 'Lecture', '1', 'false', 'false', 'false', 'true', 'false', '1700', '1750', 'Olsson Hall 005', '26', '45\n'], ['CS', '1501', '003', 'Special Topics in Computer Science', 'Collin/Cyrus', 'Lecture', '1', 'false', 'false', 'false', 'true', 'false', '1700', '1750', 'Thornton Hall D223', '9', '30\n'], ['CS', '2102', '001', 'Discrete Mathematics', 'David Edwards+1', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1230', '1345', 'Mechanical Engr Bldg 205', '147', '148\n'], ['CS', '2102', '002', 'Discrete Mathematics', 'David Edwards+1', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1400', '1515',
'Mechanical Engr Bldg 205', '147', '148\n'], ['CS', '2110', '001', 'Software Development Methods', 'David Edwards', 'Lecture', '3', 'true', 'false', 'true', 'false', 'true', '1000', '1050', 'Thornton Hall E303', '97', '100\n'], ['CS', '2110', '003', 'Software Development Methods', 'Nada Basit', 'Lecture', '3', 'true', 'false', 'true', 'false', 'true', '1300', '1350', 'Mechanical Engr Bldg 205', '146', '148\n'], ['CS', '2110', '101', 'Software Development Methods', 'Nada Basit', 'Laboratory', '0', 'true', 'false', 'false', 'false', 'false', '1900', '2045', 'Rice Hall 130', '92', '110\n'], ['CS', '2110', '102', 'Software Development Methods', 'Nada Basit', 'Laboratory', '0', 'false', 'true', 'false', 'false', 'false', '1900', '2045', 'Rice Hall 130', '97', '110\n'], ['CS', '2110', '103', 'Software Development Methods', 'Nada Basit', 'Laboratory', '0', 'true', 'false', 'false', 'false', 'false', '1700', '1845', 'Rice Hall 130', '106', '110\n'], ['CS', '2110', '104', 'Software Development Methods',
'Nada Basit', 'Laboratory', '0', 'false', 'true', 'false', 'false', 'false', '1715', '1900', 'Rice Hall 130', '109', '110\n'], ['CS', '2150', '001', 'Program and Data Representation', 'Mark Floryan', 'Lecture', '3', 'true', 'false', 'true', 'false', 'true', '1400', '1450', 'Wilson Hall 301', '163', '175\n'], ['CS', '2150', '002', 'Program and Data Representation', 'Aaron Bloomfield', 'Lecture', '3', 'true', 'false', 'true', 'false', 'true', '1300', '1350', 'Rice Hall 130', '137', '140\n'], ['CS', '2150', '101', 'Program and Data Representation', 'Aaron Bloomfield', 'Laboratory', '0', 'false', 'true', 'false', 'false', 'false', '930', '1045', 'Olsson Hall 001', '41', '45\n'], ['CS', '2150', '102', 'Program and Data Representation', 'Aaron Bloomfield', 'Laboratory', '0', 'false', 'true', 'false', 'false', 'false', '1100', '1215', 'Olsson Hall 001', '44', '45\n'], ['CS', '2150', '103', 'Program and Data Representation', 'Aaron Bloomfield', 'Laboratory', '0', 'false', 'true', 'false', 'false', 'false', '1230', '1345', 'Olsson Hall 001', '44', '45\n'], ['CS', '2150', '104', 'Program and Data Representation', 'Aaron Bloomfield', 'Laboratory', '0', 'false', 'true', 'false', 'false', 'false', '1400',
'1515', 'Olsson Hall 001', '44', '45\n'], ['CS', '2150', '105', 'Program and Data Representation', 'Aaron Bloomfield', 'Laboratory', '0', 'false', 'true', 'false', 'false', 'false', '1530', '1645', 'Olsson Hall 001', '44', '45\n'], ['CS', '2150', '106', 'Program and Data Representation', 'Aaron Bloomfield', 'Laboratory', '0', 'false', 'true', 'false', 'false', 'false', '1700', '1815', 'Olsson Hall 001', '43', '45\n'], ['CS', '2150', '107', 'Program and Data Representation', 'Aaron Bloomfield', 'Laboratory', '0', 'false', 'true', 'false', 'false', 'false', '1830', '1945', 'Olsson Hall 001', '40', '45\n'], ['CS', '2190', '001', 'Computer Science Seminar', 'Thomas Horton', 'Lecture', '1', 'false', 'false', 'false', 'true', 'false', '1530', '1620', 'Physics Bldg 203', '207', '210\n'], ['CS', '3205', '001', 'HCI in Software Development', 'Mary Smith', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1100', '1215', 'Olsson Hall 009', '75', '80\n'], ['CS', '3330', '001', 'Computer Architecture', 'Charles Reiss', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1100', '1215', 'Olsson Hall 120', '125', '135\n'], ['CS', '3330', '102', 'Computer Architecture', 'Charles Reiss', 'Laboratory', '0', 'false', 'false', 'true', 'false', 'false', '1530', '1645', 'Olsson Hall 001', '40', '44\n'], ['CS', '3330', '103', 'Computer Architecture', 'Charles Reiss', 'Laboratory', '0', 'false', 'false', 'true', 'false', 'false', '1700', '1815', 'Olsson Hall 001', '40', '44\n'], ['CS', '3330', '104', 'Computer Architecture', 'Charles Reiss', 'Laboratory', '0', 'false', 'false', 'true', 'false', 'false', '1830', '1945', 'Olsson Hall 001', '40', '44\n'], ['CS', '3330', '105', 'Computer Architecture', 'Charles Reiss', 'Laboratory', '0', 'false', 'false', 'true', 'false', 'false', '1230', '1345', 'Olsson Hall 001', '41', '44\n'], ['CS', '4102', '001', 'Algorithms', 'Kong-Cheng Wong', 'Lecture', '3', 'true', 'false', 'true', 'false', 'false', '1400', '1515', 'Clark Hall 108', '133', '140\n'], ['CS', '4434', '001', 'Dependable Computing Systems', 'Homa Alemzadeh', 'Lecture', '3', 'true', 'false', 'true', 'false', 'true', '900', '950', 'Thornton Hall E304', '2', '7\n'], ['CS', '4444', '001', 'Introduction to Parallel Computing', 'Andrew Grimshaw', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '930', '1045', 'Thornton Hall E316', '18', '30\n'], ['CS', '4457', '001', 'Computer Networks', 'Cameron Whitehouse', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1530', '1645', 'Olsson Hall 009', '33', '47\n'], ['CS', '4501', '002', 'Special Topics in Computer Science', 'Ahmed
Ibrahim', 'Lecture', '3', 'true', 'false', 'true', 'false', 'false', '1700', '1815', 'Olsson Hall 120', '73', '80\n'], ['CS', '4501', '003', 'Special Topics in Computer Science', 'Connelly Barnes', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1530', '1645', 'Rice Hall 130', '70', '96\n'], ['CS', '4610', '001', 'Programming Languages', 'Kevin Angstadt', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1230', '1345', 'Olsson Hall 011', '29', '40\n'], ['CS', '4630', '001', 'Defense Against the Dark Arts', 'Charles Reiss', 'Lecture', '3', 'true', 'false', 'true', 'false', 'false', '1530', '1645', 'Rice Hall 130', '65', '90\n'], ['CS', '4720', '001', 'Mobile Application Development', 'Mark Sherriff', 'Lecture', '3', 'true', 'false', 'true', 'false', 'true', '1100', '1150', 'Olsson Hall 120', '79', '80\n'], ['CS', '4730', '001', 'Computer Game Design', 'Mark Floryan', 'Lecture', '3', 'true', 'false', 'true', 'false', 'false', '1100', '1150', 'Mechanical Engr Bldg 341', '67',
'72\n'], ['CS', '4730', '100', 'Computer Game Design', 'Mark Floryan', 'Laboratory', '0', 'false', 'false', 'false', 'false', 'true', '1130', '1250', 'Rice Hall 340', '32', '36\n'], ['CS', '4730', '101', 'Computer Game Design', 'Mark Floryan', 'Laboratory', '0', 'false', 'false', 'false', 'false', 'true', '1000', '1120', 'Rice Hall 340', '35', '36\n'], ['CS', '4753', '001', 'Electronic Commerce Technologies', 'Alfred Weaver', 'Lecture', '3', 'true', 'false', 'true', 'false', 'false', '1530', '1645', 'Thornton Hall E316', '74', '80\n'], ['CS', '4971', '001', 'Capstone Practicum II', 'Aaron Bloomfield', 'Practicum', '3', 'true', 'false', 'true', 'false', 'true', '1000', '1050', 'Rice Hall 130', '92', '110\n'], ['CS', '5014', '001', 'Computation as a Research Tool', 'Katherine Holcomb', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1530', '1645', 'Thornton Hall E303', '66', '70\n'], ['CS', '5014', '003', 'Computation as a Research Tool', 'Thomas Hall', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1530', '1645', 'Chemical Engineering Bldg 005', '12', '70\n'], ['CS', '6160', '001', 'Theory of Computation', 'Mohammad Mahmoody Ghidary', 'Lecture', '3', 'true', 'false', 'true', 'false', 'false', '1700', '1815', 'Contact Department', '4', '10\n'], ['CS', '6434', '001', 'Dependable Computing Systems', 'Homa Alemzadeh', 'Lecture', '3', 'true', 'false', 'true', 'false', 'true', '900', '950', 'Thornton Hall E304', '1', '5\n'], ['CS', '6444', '001', 'Introduction to Parallel Computing', 'Andrew Grimshaw', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '930', '1045', 'Thornton Hall E316', '10', '30\n'], ['CS', '6501', '001', 'Special Topics in Computer Science', 'Kai-Wei Chang', 'Lecture', '3', 'true', 'false', 'true', 'false', 'false', '1700', '1815', 'Olsson Hall 009', '42', '60\n'], ['CS', '6501', '002', 'Special Topics in Computer Science', 'Jack Davidson', 'Lecture', '3', 'true', 'false', 'true', 'false', 'false', '1100', '1215', 'Rice Hall 032', '16', '32\n'], ['CS', '6501', '004', 'Special Topics in Computer Science', 'Vicente Ordonez-Roman', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1230', '1345', 'Thornton Hall E316', '32', '65\n'], ['CS', '6501', '005', 'Special Topics in Computer Science', 'Kevin Sullivan', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1400', '1515', 'Thornton Hall E303', '21', '50\n'], ['CS', '6501', '006', 'Special Topics in Computer Science', 'Lu Feng', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '930', '1045', 'Rice Hall 340', '11', '15\n'], ['CS', '6501', '007', 'Special Topics in Computer Science', 'Dimitrios Diochnos', 'Lecture', '3', 'true', 'false', 'true', 'false', 'false', '1530', '1645', 'Rice Hall 340', '18', '30\n'], ['CS', '6501', '008', 'Special Topics in Computer Science', 'David Evans', 'Lecture', '3', 'false', 'false', 'false', 'false', 'true', '930', '1200', 'Thornton Hall D115', '17', '30\n'], ['CS', '6501', '009', 'Special Topics in Computer Science', 'John Stankovic', 'Lecture', '3', 'true', 'false', 'true', 'false', 'false', '930', '1045', 'Rice Hall 340', '23', '30\n'], ['CS', '6501', '011', 'Special Topics in Computer Science', 'Baishakhi Ray', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1530', '1645', 'Rice Hall 340', '7', '30\n'], ['CS', '6501', '012', 'Special Topics in Computer Science', 'Hongning Wang', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1230', '1345', 'Rice Hall 340', '29', '34\n'], ['CS', '6750', '001', 'Database Systems', 'Abdeltawab Hendawi', 'Lecture', '3', 'false', 'true', 'false', 'true', 'false', '1700', '1815', 'Olsson Hall 009', '18', '60\n']]