I'm a mechanical engineer and not that I am good at it but just studying and creating simple programs for my work efficiency. Last 8 months while working for my current job, I made 6 programs. the programs are really helpful (to me I mean, they've saved enormous time of mine), and then today I just realized, I don't know where I am heading to. I got some books about python and data analysis both in English and Korean but always stopped at the beginning (basic skill parts) because some other life excuses. So I'm thinking of literally just dictating examples on the books instead. I wonder, if I have.. that mojo to become a sw developer, or at least a career using programming skills. Not that I would give up my current career since there are tons of super genius SWEs. But yet, I want to leave the door open and in case if there's anything happens. I'm dead serious, I've been thinking about this and started studying.. more like using python since 2020 I think. I know there's reddit and others to ask but, I've been using Korean Blind since they started their service and this is more comfortable. This is what I can do so far. Of course I have googled some parts - like io library and packet. what the hall are they lol... but yeah... So this program, I create an excel file about each part to input our ERP system, but also need to input the part's inofrmation to our CAD program, and then a pdf form to track any design change history. So this program reads the excel file, and create xml files and pdf that has already written the part name and number and your initial, date for new parts. liblist = ['import xml.etree.ElementTree as et', 'import openpyxl as xl', 'import os', 'from datetime import date as dt', 'import io', 'from tkinter import filedialog, Tk', 'from pypdf import PdfWriter, PdfReader', 'from reportlab.pdfgen import canvas', 'from reportlab.lib.pagesizes import letter', 'root = Tk()', 'root.withdraw()'] for lib in liblist: print('LOADING LIBRARIES %s/%s '\ %(liblist.index(lib)+1, len(liblist)), end = '\r') exec(lib) print(' ', end = '\r') # loading BOMs root.fn = filedialog.askopenfilename(initialdir = (os.getcwd()), title = ('SELECT ITEM MASTER FILE')) if len(root.fn) == 0: print('FILE NOT SELECTED ') else: if '.csv' in str(root.fn): print('CSV FORMAT IS NOT SUPPORTED ') else: wb = xl.load_workbook(root.fn) sheet=wb.active if 'Part No.' in sheet['A1'].value: drwby = input('TYPE YOUR INITIAL - ') for i in range(1, sheet.max_row + 1): if sheet['C' + str(i)].value == None: maxrow = i break else: maxrow = sheet.max_row + 1 # PARAMETERS for PART paramlist = ['PART_NAME', 'DESCRIPTION', 'DRAWN', 'CLASS', 'TYPE', 'DEPARTMENT', 'DRAWING_SIZE', 'UNIT'] for i in range(2, maxrow): if sheet['B' + str(i)].value == 'A': valuelist = [sheet['C' + str(i)].value, sheet['J' + str(i)].value, drwby, sheet['I' + str(i)].value, sheet['G' + str(i)].value, sheet['H' + str(i)].value, sheet['E' + str(i)].value, sheet['F' + str(i)].value] rootelmnt = et.Element('CreoParamSet') for no in range(len(paramlist)): paramset = et.SubElement(rootelmnt, 'Parameter', Name=paramlist[no]) dtelmnt = et.SubElement(paramset, 'DataType') dtelmnt.text = 'String' dtelmnt = et.SubElement(paramset, 'Value') dtelmnt.text = str(valuelist[no] if type(valuelist[no]) == str or type(valuelist[no]) == int else ' ') tree = et.ElementTree(rootelmnt) tree.write('prt_' + str(sheet['A' + str(i)].value) + '.xml', encoding ='utf-8', xml_declaration = True) # CREATING pdf file if sheet['B' + str(i)].value == 'A' and sheet['G' + str(i)].value != 4: packet = io.BytesIO() can = canvas.Canvas(packet, pagesize=letter) pos = [[-227, -60], [-230, -373], [287, -40], [674, -40], [405, -165]] ftszlist = [15, 10, 15, 14] ftszlist.insert(2, 13) if len(valuelist[0]) > 27 else ftszlist.insert(2, 15) datalist = [dt.today().strftime("%m/%d/%Y"), "JL, " + dt.today().strftime("%m/%d/%y"), valuelist[0], sheet['A' + str(i)].value, "INITIAL RELEASE"] for pg in range(2): for data in datalist if pg == 0 else datalist[2:]: can.rotate(180) if datalist.index(data) <= 1 else can.rotate(90) can.setFont('Helvetica', ftszlist[datalist.index(data)]) can.drawString(pos[datalist.index(data)][0], pos[datalist.index(data)][1], data) can.rotate(180) if datalist.index(data) <= 1 else can.rotate(270) can.showPage() can.save() packet.seek(0) new_pdf = PdfReader(packet) f = open('FORM - DO NOT DELETE OR RENAME.pdf', "rb") existing_pdf = PdfReader(f) output = PdfWriter() page = existing_pdf.pages[0] page.merge_page(new_pdf.pages[0]) output.add_page(page) page = existing_pdf.pages[1] page.merge_page(new_pdf.pages[1]) output.add_page(page) output_stream = open(sheet['A' + str(i)].value + ".pdf", "wb") output.write(output_stream) output_stream.close() f.close() os.startfile('ECN_' + sheet['A' + str(i)].value + ".pdf") print("\nPDF FORM FOR ALL NEW ITEMS ON THE LIST ARE CREATED AND SAVED IN XML FORMAT") else: print('THE SELECTED FILE IS NOT IN ITEM MASTER FORMAT') asmpn = input('PRESS <ENTER> TO EXIT') TC: 120k
Don’t import libraries like this.
Is it bad? I never did like this, except this time only because I wanted to print out how many libraries are loaded especially it's a 270 MB exe program after I turned it to an exe file - so if there's anyone who uses my program can see the progress. It takes more than 40 seconds and so I inserted print right under every importing sentence, seemed unorganized so edited that way.
Tech Industry
3h
500
The man I love hates me because I’m Vietnamese
World Conflicts
Yesterday
765
Peaceful Protest Hasn’t Worked and Has Been Met With Aggression.
Tech Industry
3d
40418
What happens when most of your team is Indian?
Tech Industry
16h
1510
Why doesn't OpenAI offshore and reduce expense by 80%
Tech Industry
6h
195
Is Israel getting bad PR the reason for banning tik tok?
pardon my english. I meant, typing the examples on the books.