What is a class? instance? Method? It's a function declaration, isn't it? I feel like I was frustrated in this field a year or two ago and was a little away from studying programming. This time, I've just returned to the class field after studying python for re-learning.
Start learning by groping while touching what kind of image it is, leaving a little about concepts, instances, object orientation, and so on. When I read the article about other people's classes, I imagined that it would be useful when doing something with the approval documents that come around at the company. ?? It is an image. For the time being, studying what theory and object-orientation are, I'll turn it around next time, and here it's convenient to use the class I imagined in such a case, right? I will publish the code created with the image.
I am an accounting member of a company in the humanities. I am fighting documents and accounts every day. The idea that the class could be used with such status was the processing of the assets that were approved and planned to be purchased. In other words, give attributes such as the approval number, the approval drafter, the department to which the drafter belongs, what assets, and how much assets. It is to be able to use it as a form at the time of settlement by processing email confirmation and posting to Excel. The approval form is constantly coming around every day, so it seems good to program it to improve efficiency. Based on this idea, I created the following code to think that python classes can be used.
What I want the program to do for the time being ① Creating an email ② Posting to Excel
qiita.rb
import openpyxl
import datetime
class assets():
def __init__(self,apdnum,apdmen,unitname,assetname,money):
self.apdnum=apdnum
self.apdmen=apdmen
self.unitname=unitname
self.assetname=assetname
self.money=money
#A function to attach a PDF to an email: We plan to add work to pick up the destination email address from the person in charge and the department in charge.
def when_mail(self):
mail=("{}{}Thank you for your hard work. I am in charge of fixed assets in the accounting department. Approval No.{}of{}About\
\n Please tell us about the situation this month if you have started using it. Also, if there is an invoice, you can also attach an invoice\
\n Thank you.".format(self.unitname,self.apdmen,self.apdnum,self.assetname))
print(mail)
def Insert_excel(self):
wb=openpyxl.load_workbook("../data/Order fixed asset management table.xlsx")
sh=wb.active
for dt_row in range(2,50):
if sh["A"+str(dt_row)].value!=None:
continue
else:
sh["A"+str(dt_row)].value=self.apdnum
sh["B"+str(dt_row)].value=self.unitname
sh["C"+str(dt_row)].value=self.apdmen
sh["D"+str(dt_row)].value=self.assetname
sh["E"+str(dt_row)].value=self.money
break
wb.save("../data/Order fixed asset management table_{}_Create johannesrome.xlsx".format(datetime.date.today()))
#The following executable program
print("Please enter a new approval form number")
apdnum_re=input()
print("Please enter the drafter of the approval form")
apdmen_re=input()
print("Please enter the department to which the drafter belongs")
unitname_re=input()
print("Please enter the name of the purchase target")
assetname_re=input()
print("Please enter the planned procurement price")
money_re=input()
m=assets(apdnum_re,apdmen_re,unitname_re,assetname_re,money_re)
m.when_mail()
m.Insert_excel()
As a code, create an asset class and give it 5 attributes. ① Approval number ② Approval drafter ② Department to which the drafter belongs ④ Name of the asset to be purchased ⑤ Purchase amount When you start the program, you will be asked for the above five inputs, and an instance will be created based on that. And the content that the mail text is created and posted to Excel.
Personally, I think this is a program that enjoys the benefits of the class. What is it like? I don't use class succession or multiple succession, but the merit of class If you have any opinions, please feel free to comment (^ ω ^). This was the first time!
Recommended Posts