Understanding the python class Struggle (1) Let's move it for the time being

Isn't the concept difficult for a class?

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.

I will touch it for the time being

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.

Processing for approval documents

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

And I made coding with the following classes

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()

Code details

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.

Personal summary

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

Understanding the python class Struggle (1) Let's move it for the time being
Python Master RTA for the time being
Let's touch Google's Vision API from Python for the time being
Use logger with Python for the time being
Until you can install blender and run it with python for the time being
I want to move selenium for the time being [for mac]
See python for the first time
Challenge image classification by TensorFlow2 + Keras 1-Move for the time being-
Try using FireBase Cloud Firestore in Python for the time being
MongoDB for the first time in Python
Let's try Linux for the first time
Challenge image classification with TensorFlow2 + Keras CNN 1 ~ Move for the time being ~
[Python] [Machine learning] Beginners without any knowledge try machine learning for the time being
For the time being, import them into jupyter
Make a histogram for the time being (matplotlib)
Run yolov4 "for the time being" on windows
I played with Floydhub for the time being
I tried python programming for the first time.
Python: Prepare a serializer for the class instance:
Try using LINE Notify for the time being
virtualenv For the time being, this is all!
I bought Sipeed Lichee Zero so I set it up for the time being
What I got into Python for the first time
I tried Python on Mac for the first time.
Molecular dynamics simulation to try for the time being
I tried python on heroku for the first time
I don't know what HEIC is. But for the time being, let's use PNG!
I will install Arch Linux for the time being.
Next to Excel, for the time being, jupyter notebook
AI Gaming I tried it for the first time
I tried running PIFuHD on Windows for the time being
[Understand in the shortest time] Python basics for data analysis
[Introduction to Reinforcement Learning] Reinforcement learning to try moving for the time being
For the time being, try using the docomo chat dialogue API
I want to create a Dockerfile for the time being.
Kaggle for the first time (kaggle ①)
Kaguru for the first time
A memorandum of understanding for the Python package management tool ez_setup
Differences C # engineers felt when learning python for the first time
Let's do it by dividing numpy without using the for statement
Java programmer tried to touch Go language (for the time being)
MoneyForward Cloud Automates time stamping [Let's let Python do the trouble]
Let's do it by multiplying numpy without using the for statement
For the time being, I want to convert files with ffmpeg !!
What is Python? What is it used for?
[Python] Check the current directory, move the directory
"The easiest Python introductory class" modified
[For self-learning] Go2 for the first time
[Python] Understanding the potential_field_planning of Python Robotics
Examine the object's class in python
What is the python underscore (_) for?
Start Django for the first time
Command for the current directory Python
Understanding python classes Struggle (2) Work That's not all, right? _ About class inheritance
For the first time in Numpy, I will update it from time to time
[Python] It was very convenient to use a Python class for a ROS program.
A useful note when using Python for the first time in a while
Since I'm free, the front-end engineer tried Python (v3.7.5) for the first time.