# e-mail 추출기
# 1.pyperclip 모듈을 사용 복사와 붙여넣기
# 2.regex만듦 , e-mail 주소 매칭
# 3. 모든 매치를 찾는다
# 4. 매칭된 String을 하나의 문자열로 만든다
# 5. 매칭된 문자열이 없으면 간단한 메세지 출력
import re
import pyperclip
# Create e-Mail regex --> VERBOSE, X
# ''' -> MultiLine
email_regex = re.compile(r'''(
[a-zA*Z0-9._%+-] + #username
@ # @sysbol
[a-zA-Z0-9.-]+ # domain name
(\.[a-zA-Z]{2,4}){1,2} # dot-something
) ''', re.VERBOSE )
# ClipBoard에 복사된 내용에서 e-Mail Pattern과 매치되는 Text를 찾음
def find_match_list():
# ctrl +c
text = pyperclip.paste()
# clip Board에 있는 List를 하나씩 꺼내 matches List에 넣음
matches = []
print("find_match_list text-> Start...")
print("find_match_list text->", text)
# email에 있는 List Append
for email in email_regex.findall(text):
matches.append(email[0])
print("find_match_list matches->", matches)
return matches
# ClipBoard에 복사
def copy_result_to_clipboard(matches):
if len(matches) > 0:
# List하나하나가 개행되어 처리
pyperclip.copy('\n'.join(matches))
print('ClipBoard에 복사 됨')
else:
print("매칭되는 Pattern이 없음")
# ClipBoard에 복사된 내용에서 e-Mail Pattern과 매치되는 Text를 찾음
def main():
matches = find_match_list()
print("main matches->", matches)
copy_result_to_clipboard(matches)
main()
# calculator.py
# 사칙연산을 수행(add,substruct,multiply) 하는 함수
def add(a,b):
return a+b
def substruct(a,b):
return a-b
def multiply(a,b):
return a*b
# calc_main3.py
# 사칙연산을 수행(add,substruct,multiply) 하는 main 만듦
import ch17.calculator as calculator3
def main():
print( 'add(10,2->' ,calculator3.add(10,2))
print(('substruct(10,2->'), calculator3.substruct(10,2))
print('multiply(10,2)->', calculator3.multiply(10,2))
main()
add(10,2-> 12
substruct(10,2-> 8
multiply(10,2)-> 20
def add(a,b):
print('service add')
return a+b
def substruct(a,b):
print('service substruct')
return a-b
def multiply(a,b):
print('service multiply')
return a*b
# calc_main_package.py
# package는 from ch17.services 형식으로 호출
from ch17.services import calculator as calculator
def main():
print( 'add(10,2->' ,calculator.add(10,2))
print(('substruct(10,2->'), calculator.substruct(10,2))
print('multiply(10,2)->', calculator.multiply(10,2))
main()
service add
add(10,2-> 12
service substruct
substruct(10,2-> 8
service multiply
multiply(10,2)-> 20
class Animal:
name = 'dog'
age = 5
# 인스턴스 생성
a1 = Animal()
print(a1.name)
print(a1.age)
a2 = Animal() #인스턴스 생성
a2.name = '원숭이'
a2.age=10
print("a1.name->",a1.name)
print("a1.age->",a1.age)
print("a2.name->",a2.name)
print("a2.age->",a2.age)
# 생성자
# 생성자는 객체가 생성될때 호출된다.
# 생성자는 멤버변수를 초기화하는 역할을 한다.
class Animal:
# 생성자, 첫번째 parameter -> self 는 예약어
def __init__(self):
self.var = '안녕하세요!'
print('Aniaml 인스턴스 객체가 생성되었습니다')
cat = Animal() #'Animal 인스턴스 객체가 생성되었습니다' 출력
print(cat.var) #'안녕하세요'출력
print(type(cat)) #'안녕하세요'출력
#클래스의 상속
class Add:
def add(self,n1, n2): #부모클래스, 슈퍼클래스
return n1+n2 #부모클래스의 메소드는 상속됨
#Calculator(Add) --> class Add 상속
class Calculatopr(Add): #자식클래스 , 서브클래스
def sub(self, n1, n2):
return n1 - n2
cal = Calculatopr()
print(cal.add(1,2)) #3이 출력됨
print(cal.sub(1,2)) #-1 이 출력됨
# 생성자
# 생성자는 객체가 생성될때 호출
# 생성자는 멤버변수를 초기화하는 역할.
class Animal(object):
#생성자, 첫번째 parameter -> self는 예약어
def __init__(self, name, age,is_hungry):
# 생성자 내부에서 self 로 받으면 자동으로 member 가 생성됨
self.name= name
self.age = age
self.is_hungry = is_hungry
print(self.name, 'Aniaml 인스턴스 객체가 생성되었습니다')
def descript(self):
print(self.name, "method called")
jeffrey = Animal("Jeffey", 2 , True)#Jeffey Aniaml 인스턴스 객체가 생성되었습니다
bruce = Animal("Bruce", 5, False) #Bruce Aniaml 인스턴스 객체가 생성되었습니다
trum = Animal("Trum", 7, True) #Trum Aniaml 인스턴스 객체가 생성되었습니다
print(jeffrey.name , jeffrey.age, jeffrey.is_hungry) #Jeffey 2 True
print(bruce.name, bruce.age, bruce.is_hungry) #Bruce 5 False
print(trum.name, trum.age , trum.is_hungry) #Trum 7 True
jeffrey.descript()