SlideShare a Scribd company logo
1 of 23
Download to read offline
Python
Study Of Landvibe
made by 김건희
오늘의 주제
Module
Exception
Outline
1. Module & Package
2. Exception
Module
함수 : 특정 행위에 대해 기술한 소스 코드
클래스 : 특정 행위와 상태를 담을 수 있는 객체를 생성하기 위한 명세서
모듈 : 함수, 클래스 등을 포함하여 독립적인 파일(.py)로 저장하여 언제든지 호
출하여 재사할 수 있는 공통 소스 코드들의 집합
Don’t Repeat Yourself!
>>> “같은 소스를 반복해서 작성하지 말라”
소스 재사용
함수 : 특정 행위에 대해 기술한 소스 코드
클래스 : 특정 행위와 상태를 담을 수 있는 객체를 생성하기 위한 명세서
모듈 : 함수, 클래스 등을 포함하여 독립적인 파일(.py)로 저장하여 언제든지 호
출하여 재사할 수 있는 공통 소스 코드들의 집합
Don’t Repeat Yourself!
>>> “같은 소스를 반복해서 작성하지 말라”
소스 재사용
Module
Module
특정 행위와 상태를 담을 수 있는 객체를 생성하
기 위한 명세서를 담은 .py 파일
1. 모듈의 정의
Module
특정 행위와 상태를 담을 수 있는 객체를 생성하
기 위한 명세서를 담은 .py 파일
1. 모듈의 정의
특정 행위 : Method
Module
특정 상태 : Attribute
특정 행위와 상태를 담을 수 있는 객체를 생성하
기 위한 명세서를 담은 .py 파일
1. 모듈의 정의
특정 행위 : Method
Module
특정 상태 : Attribute
특정 행위와 상태를 담을 수 있는 객체를 생성하
기 위한 명세서를 담은 .py 파일
1. 모듈의 정의
특정 행위 : Method
명세서 : Class Name
Module
특정 행위와 상태를 담을 수 있는 객체를 생성하
기 위한 명세서를 담은 .py 파일
1. 모듈의 정의
특정 행위 : Method1
특정 상태 : Attribute1
명세서 : Class1
특정 행위 : Method2
특정 상태 : Attribute2
명세서 : Class2
특정 행위 : Method3
특정 상태 : Attribute3
명세서 : Class3
.py 파일
Module
모듈들을 특정 기준에 따라 모아 놓은 단위
2. package
모듈
패키지
Module
import <모듈명>
from <패키지.모듈명> import <클래스, 메소드, 함수>
from <패키지.모듈명> import <클래스, 메소드, 함수> as <alias name>
2. 모듈 사용하기
BasicPracitce/fibo.py
BasicPracitce/ModuleEx.py
Module
__name__ : 모듈 혹은 함수의 이름을 가지고 있는 함수, 해당 모듈이 시작점
이면 “__main__”을 리턴한다
2. 모듈 사용하기
BasicPracitce/ModuleEx.py
Module
sys 모듈 사용하기
python <모듈.py> <argv…> : 모듈.py = argv[0], argv는 array
2. 모듈 사용하기
Exception
문법 실수, 잘못된 타입 사용 등의 소스코드가 잘못됬을 때 발생하는 것
1. 에러 (Errors)
Exception
소스 실행 중에 에러가 발생하는 경우
2. 예외 (Exception)
예외의 종류
https://docs.python.org/3.2/library/exceptions.html
에러와 예외의 본질은 같으나 용도의 차이가 있습니다.
> 에러를 다루기 위한 것이 예외라고 생각하고 넘어갑시다.
Exception
try:
<예외 발생 가능성이 있는 문장>
except <예외 종류> :
<예외 처리 문장>
except (예외1, 예외2) :
<예외 처리 문장>
except <예외> as <인자> :
<예외 처리 문장>
else:
<예외가 발생하지 않은 경우, 수행할 문장>
finally:
<예외 발생 유무에 상관없이 try 블록 이후에 사용할 문장>
3. 예외 처리
Exception
3. 예외 처리
예시
Exception
3. 예외 처리
예시
Exception
3. 예외 처리
예시
Exception
3. 예외 처리
주의 할것!
Exception
4. raise 구문
raise [Exception] : 해당 예외를 발생시킵니다.
raise [Exception(data)] : 예외 발생 시 관련 데이터를 전달합니다.
raise : 발생된 예외를 상위로 전달합니다.
5. 사용자 정의 예외
Exception 객체를 상속받아 생성
class ExceptionName(Exception):
pass
Exception
4, 5. raise, 사용자 정의 예외
예시
코드랩 예고
땅스타그램!

More Related Content

Viewers also liked

땅울림 파이썬 스터디 intro
땅울림 파이썬 스터디 intro땅울림 파이썬 스터디 intro
땅울림 파이썬 스터디 intro건희 김
 
Python if loop-function
Python if loop-functionPython if loop-function
Python if loop-function건희 김
 
Python codelab3
Python codelab3Python codelab3
Python codelab3건희 김
 
Python(basic)
Python(basic)Python(basic)
Python(basic)POSTECH
 
Python datatype
Python datatypePython datatype
Python datatype건희 김
 
Effective response to adverse weather conditions using SolarPulse
Effective response to adverse weather conditions using SolarPulseEffective response to adverse weather conditions using SolarPulse
Effective response to adverse weather conditions using SolarPulseMachinePulse
 
빅데이터의 개념과 이해 그리고 활용사례 (Introduction to big data and use cases)
빅데이터의 개념과 이해 그리고 활용사례 (Introduction to big data and use cases)빅데이터의 개념과 이해 그리고 활용사례 (Introduction to big data and use cases)
빅데이터의 개념과 이해 그리고 활용사례 (Introduction to big data and use cases)Wonjin Lee
 

Viewers also liked (9)

모듈
모듈모듈
모듈
 
Python 01
Python 01Python 01
Python 01
 
땅울림 파이썬 스터디 intro
땅울림 파이썬 스터디 intro땅울림 파이썬 스터디 intro
땅울림 파이썬 스터디 intro
 
Python if loop-function
Python if loop-functionPython if loop-function
Python if loop-function
 
Python codelab3
Python codelab3Python codelab3
Python codelab3
 
Python(basic)
Python(basic)Python(basic)
Python(basic)
 
Python datatype
Python datatypePython datatype
Python datatype
 
Effective response to adverse weather conditions using SolarPulse
Effective response to adverse weather conditions using SolarPulseEffective response to adverse weather conditions using SolarPulse
Effective response to adverse weather conditions using SolarPulse
 
빅데이터의 개념과 이해 그리고 활용사례 (Introduction to big data and use cases)
빅데이터의 개념과 이해 그리고 활용사례 (Introduction to big data and use cases)빅데이터의 개념과 이해 그리고 활용사례 (Introduction to big data and use cases)
빅데이터의 개념과 이해 그리고 활용사례 (Introduction to big data and use cases)
 

Similar to Python module

Python3 6장 모듈만들기
Python3 6장 모듈만들기Python3 6장 모듈만들기
Python3 6장 모듈만들기Jihoon Kong
 
Common cartridge 요약본
Common cartridge 요약본Common cartridge 요약본
Common cartridge 요약본Se Joung Kim
 
Java, android 스터티2
Java, android 스터티2Java, android 스터티2
Java, android 스터티2Heejun Kim
 
Python class
Python classPython class
Python classHerren
 
Custom Xcode Template (with VIPER)
Custom Xcode Template (with VIPER)Custom Xcode Template (with VIPER)
Custom Xcode Template (with VIPER)Bongwon Lee
 
Api design for c++ ch3 pattern
Api design for c++ ch3 patternApi design for c++ ch3 pattern
Api design for c++ ch3 patternjinho park
 
Api design for c++ pattern
Api design for c++ patternApi design for c++ pattern
Api design for c++ patternjinho park
 
거 XE 모듈 개발하기 좋은 날씨네 - XECon + PHPFest 2014
거 XE 모듈 개발하기 좋은 날씨네 - XECon + PHPFest 2014거 XE 모듈 개발하기 좋은 날씨네 - XECon + PHPFest 2014
거 XE 모듈 개발하기 좋은 날씨네 - XECon + PHPFest 2014승엽 신
 
Spring di chapter2
Spring di chapter2Spring di chapter2
Spring di chapter2흥래 김
 
Effective java 1 and 2
Effective java 1 and 2Effective java 1 and 2
Effective java 1 and 2중선 곽
 
파이썬 객체 클래스 이해하기
파이썬  객체 클래스 이해하기파이썬  객체 클래스 이해하기
파이썬 객체 클래스 이해하기Yong Joon Moon
 
디자인패턴 1~13
디자인패턴 1~13디자인패턴 1~13
디자인패턴 1~13Shin heemin
 
Head first디자인패턴 1~13_희민_호준
Head first디자인패턴 1~13_희민_호준Head first디자인패턴 1~13_희민_호준
Head first디자인패턴 1~13_희민_호준HoJun Sung
 
Java 강의자료 ed11
Java 강의자료 ed11Java 강의자료 ed11
Java 강의자료 ed11hungrok
 
Java, android 스터티1
Java, android 스터티1Java, android 스터티1
Java, android 스터티1Heejun Kim
 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web ComponentsEunYoung Kim
 

Similar to Python module (20)

Python3 6장 모듈만들기
Python3 6장 모듈만들기Python3 6장 모듈만들기
Python3 6장 모듈만들기
 
Python class
Python classPython class
Python class
 
Common cartridge 요약본
Common cartridge 요약본Common cartridge 요약본
Common cartridge 요약본
 
Java, android 스터티2
Java, android 스터티2Java, android 스터티2
Java, android 스터티2
 
Python class
Python classPython class
Python class
 
Custom Xcode Template (with VIPER)
Custom Xcode Template (with VIPER)Custom Xcode Template (with VIPER)
Custom Xcode Template (with VIPER)
 
Java_05 class
Java_05 classJava_05 class
Java_05 class
 
Java class
Java classJava class
Java class
 
Api design for c++ ch3 pattern
Api design for c++ ch3 patternApi design for c++ ch3 pattern
Api design for c++ ch3 pattern
 
Api design for c++ pattern
Api design for c++ patternApi design for c++ pattern
Api design for c++ pattern
 
거 XE 모듈 개발하기 좋은 날씨네 - XECon + PHPFest 2014
거 XE 모듈 개발하기 좋은 날씨네 - XECon + PHPFest 2014거 XE 모듈 개발하기 좋은 날씨네 - XECon + PHPFest 2014
거 XE 모듈 개발하기 좋은 날씨네 - XECon + PHPFest 2014
 
Spring di chapter2
Spring di chapter2Spring di chapter2
Spring di chapter2
 
Effective java 1 and 2
Effective java 1 and 2Effective java 1 and 2
Effective java 1 and 2
 
파이썬 객체 클래스 이해하기
파이썬  객체 클래스 이해하기파이썬  객체 클래스 이해하기
파이썬 객체 클래스 이해하기
 
디자인패턴 1~13
디자인패턴 1~13디자인패턴 1~13
디자인패턴 1~13
 
Head first디자인패턴 1~13_희민_호준
Head first디자인패턴 1~13_희민_호준Head first디자인패턴 1~13_희민_호준
Head first디자인패턴 1~13_희민_호준
 
Java 강의자료 ed11
Java 강의자료 ed11Java 강의자료 ed11
Java 강의자료 ed11
 
Java, android 스터티1
Java, android 스터티1Java, android 스터티1
Java, android 스터티1
 
12books
12books12books
12books
 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
 

Python module

  • 1. Python Study Of Landvibe made by 김건희 오늘의 주제 Module Exception
  • 2. Outline 1. Module & Package 2. Exception
  • 3. Module 함수 : 특정 행위에 대해 기술한 소스 코드 클래스 : 특정 행위와 상태를 담을 수 있는 객체를 생성하기 위한 명세서 모듈 : 함수, 클래스 등을 포함하여 독립적인 파일(.py)로 저장하여 언제든지 호 출하여 재사할 수 있는 공통 소스 코드들의 집합 Don’t Repeat Yourself! >>> “같은 소스를 반복해서 작성하지 말라” 소스 재사용
  • 4. 함수 : 특정 행위에 대해 기술한 소스 코드 클래스 : 특정 행위와 상태를 담을 수 있는 객체를 생성하기 위한 명세서 모듈 : 함수, 클래스 등을 포함하여 독립적인 파일(.py)로 저장하여 언제든지 호 출하여 재사할 수 있는 공통 소스 코드들의 집합 Don’t Repeat Yourself! >>> “같은 소스를 반복해서 작성하지 말라” 소스 재사용 Module
  • 5. Module 특정 행위와 상태를 담을 수 있는 객체를 생성하 기 위한 명세서를 담은 .py 파일 1. 모듈의 정의
  • 6. Module 특정 행위와 상태를 담을 수 있는 객체를 생성하 기 위한 명세서를 담은 .py 파일 1. 모듈의 정의 특정 행위 : Method
  • 7. Module 특정 상태 : Attribute 특정 행위와 상태를 담을 수 있는 객체를 생성하 기 위한 명세서를 담은 .py 파일 1. 모듈의 정의 특정 행위 : Method
  • 8. Module 특정 상태 : Attribute 특정 행위와 상태를 담을 수 있는 객체를 생성하 기 위한 명세서를 담은 .py 파일 1. 모듈의 정의 특정 행위 : Method 명세서 : Class Name
  • 9. Module 특정 행위와 상태를 담을 수 있는 객체를 생성하 기 위한 명세서를 담은 .py 파일 1. 모듈의 정의 특정 행위 : Method1 특정 상태 : Attribute1 명세서 : Class1 특정 행위 : Method2 특정 상태 : Attribute2 명세서 : Class2 특정 행위 : Method3 특정 상태 : Attribute3 명세서 : Class3 .py 파일
  • 10. Module 모듈들을 특정 기준에 따라 모아 놓은 단위 2. package 모듈 패키지
  • 11. Module import <모듈명> from <패키지.모듈명> import <클래스, 메소드, 함수> from <패키지.모듈명> import <클래스, 메소드, 함수> as <alias name> 2. 모듈 사용하기 BasicPracitce/fibo.py BasicPracitce/ModuleEx.py
  • 12. Module __name__ : 모듈 혹은 함수의 이름을 가지고 있는 함수, 해당 모듈이 시작점 이면 “__main__”을 리턴한다 2. 모듈 사용하기 BasicPracitce/ModuleEx.py
  • 13. Module sys 모듈 사용하기 python <모듈.py> <argv…> : 모듈.py = argv[0], argv는 array 2. 모듈 사용하기
  • 14. Exception 문법 실수, 잘못된 타입 사용 등의 소스코드가 잘못됬을 때 발생하는 것 1. 에러 (Errors)
  • 15. Exception 소스 실행 중에 에러가 발생하는 경우 2. 예외 (Exception) 예외의 종류 https://docs.python.org/3.2/library/exceptions.html 에러와 예외의 본질은 같으나 용도의 차이가 있습니다. > 에러를 다루기 위한 것이 예외라고 생각하고 넘어갑시다.
  • 16. Exception try: <예외 발생 가능성이 있는 문장> except <예외 종류> : <예외 처리 문장> except (예외1, 예외2) : <예외 처리 문장> except <예외> as <인자> : <예외 처리 문장> else: <예외가 발생하지 않은 경우, 수행할 문장> finally: <예외 발생 유무에 상관없이 try 블록 이후에 사용할 문장> 3. 예외 처리
  • 21. Exception 4. raise 구문 raise [Exception] : 해당 예외를 발생시킵니다. raise [Exception(data)] : 예외 발생 시 관련 데이터를 전달합니다. raise : 발생된 예외를 상위로 전달합니다. 5. 사용자 정의 예외 Exception 객체를 상속받아 생성 class ExceptionName(Exception): pass
  • 22. Exception 4, 5. raise, 사용자 정의 예외 예시