I am learning more about python using the book "Automate The Boring Stuff". The problem I completed was "Excel To CSV Converter". I want to kick bad habits to the curb, and make sure I'm learning the best python practices to further my development. I would really appreciate feedback on code efficiency, and code neatness. Is my code PEP-8 compliant? Does it implement all the best practices possible? Thank you in advance, all feedback is appreciated and considered!
import openpyxl, csv, os, re, shutil
path = os.getcwd()
new_path = path + '\\' + 'csv_files'
for excel in os.listdir('.'):
if not excel.endswith('xlsx'):
continue
workbook = openpyxl.load_workbook(excel)
for sheets in workbook.sheetnames:
wb_name = re.sub('.xlsx', '', excel)
csv_name = wb_name + '_' + sheets + '.csv'
csv_file = open(csv_name, 'w', newline='')
csv_writer = csv.writer(csv_file)
sheet = workbook.active
for row_number in range(1, sheet.max_row + 1):
row_info = []
for col_number in range(1, sheet.max_column + 1):
data = sheet.cell(row=row_number, column=col_number).value
row_info.append(data)
csv_writer.writerow(row_info)
csv_file.close()
shutil.move(os.path.join(path, csv_name), os.path.join(new_path, csv_name))