Last active
April 2, 2018 10:00
-
-
Save bakatrouble/28d7df662563927c8c65f98f3cc95921 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # source data files: http://spreadsheet_reader.drop.bakatrouble.pw/ | |
| /home/bakatrouble/.virtualenvs/sandbox/bin/python3 /home/bakatrouble/dev/sandbox/q.py | |
| === XLS === | |
| Тестов, Тест, Тестович, test, [email protected] | |
| Иванов, Иван, Иванович, test2, [email protected] | |
| === CSV === | |
| Тестов, Тест, Тестович, test, [email protected] | |
| Иванов, Иван, Иванович, test2, [email protected] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def csv_read(): | |
| import csv | |
| with open('data.csv', encoding='cp1251') as f: | |
| reader = csv.reader(f, delimiter=';', quotechar='"') | |
| next(reader) | |
| for row in reader: | |
| last_name = row[0] | |
| first_name = row[1] | |
| father_name = row[2] | |
| group = row[3] | |
| email = row[4] | |
| print(f'{last_name}, {first_name}, {father_name}, {group}, {email}') | |
| def xls_read(): | |
| import xlrd | |
| book = xlrd.open_workbook('data.xls') | |
| sheet = book.sheet_by_index(0) | |
| for i in range(1, sheet.nrows): | |
| row = sheet.row(i) | |
| last_name = row[0].value | |
| first_name = row[1].value | |
| father_name = row[2].value | |
| group = row[3].value | |
| email = row[4].value | |
| print(f'{last_name}, {first_name}, {father_name}, {group}, {email}') | |
| if __name__ == '__main__': | |
| print('=== XLS ===') | |
| xls_read() | |
| print('\n=== CSV ===') | |
| csv_read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment