본문 바로가기
IT/프로그래밍

파이썬 메일 보내기, 기본 문법 - 내 일을 바꾸는 업무 자동화 4장

by nutrient 2021. 5. 29.
728x90
728x170

 

 

 

4.1-1

def print_hello():
    print('Hello world!')
    print('It\'s me')

print_hello()
print_hello()
print_hello()

 

4.2-1

def my_sum(a, b):
    res = a + b
    return res

res = my_sum(10, 20)
print(res)

 

4.2-1_scope

num = 1

def my_num():
    num = 0

my_num()
print(num)

 

4.4-1

class Email:
    sender = ""

    def send_mail(self, recv, subject, contents):
        print("From:\t" + self.sender)
        print("To:\t" + recv)
        print("Subject:" + subject)
        print("Contents")
        print(contents)
        print("-"*20)

e = Email()
e.sender = "alghost.lee@gmail.com"
recv_list = ['1@gmail.com', '2@gmail.com', '3@gmail.com']

for recv in recv_list:
    e.send_mail(recv, "Welcome!", "This is contents")

 

4.6-1

print('Hello World!')
# 한 줄 주석입니다.

'''
여러 줄 주석입니다.1
여러 줄 주석입니다.2
여러 줄 주석입니다.3
여러 줄 주석입니다.4
'''
print('Hello World! 2')

 

4.6-2

val = 100
print(val)
val += 100
print(val)
val -= 10
print(val)
val *= 3
print(val)
val /= 5
print(val)

 

auto.py

from my_email import Email

e = Email()
e.sender = "example@gmail.com"
recv_list = ['1@gmail.com', '2@gmail.com', '3@gmail.com']

for recv in recv_list:
    e.send_mail(recv, "Welcome!", "This is contents")


 

my_email.py

class Email:
    sender = ""

    def send_mail(self, recv, subject, contents):
        print("From:\t" + self.sender)
        print("To:\t" + recv)
        print("Subject:" + subject)
        print("Contents")
        print(contents)
        print("-"*20)

 

my_excel.py

class Excel():
    def get_data(self):
        return ['example', 'python', 'pyEmail']

 

my_web.py

class Web():
    def get_result(self, keyword):
        result = []
        for t in range(10):
            result.append(keyword + " result: " + str(t))

        return result
728x90
그리드형

댓글