Development/Python
2BPerfect...8
Kirok Kim
2022. 1. 25. 11:08
모듈
마술 명령어
%whos 저장된 변수 보기
%%writefile [-a] file.py
a옵션을 사용하면 추가하고 사용하지 않으면 덮어씀
%load file.py 불러오기
%run file.py 코드 읽어서 코드 셀에 표시
# 모듈을 불러오고 모듈.변수 모듈.함수 모듈.클래스명을 사용해야하지만
from my_area import * # 이런식으로 불러와 바로 변수와 메서드 클래스를 쓸 수 있다.
print('pi=',PI)
print('sqare area =',square_area(5))
from 모듈명 import 함수명 as 별명
if __name__=="__main__": # 직접 실행할때만 실행됨 import 할때는 실행 안됨.
print("Do it")
func(3)
func(4)
else:
func(5) # 임포트 됐을 때만 실행됨
# 내장 모듈
## 난수 발생 모듈
import random
.random()
.randint(a,b) a<=정수<=b
.randrange(start,stop,step)
.choice(seq) seq 에서 임의의 항목을 반환
.sample(pop,k) 시퀀스로 이뤄진 모집단에서 중복되지 않은 k개의 인자 반환
## 날짜 및 시간 관련 처리 모듈
import datetime
datetime.date(year,month,day)
datetime.time(hour,minute,second)
datetime.datetime(year,month,day,hour,minute,second)
## 달력 모듈
import calendar
012346
월화수목금토일
.month
.isleap(y) 윤년 판단
.weekday(y,m,d) 요일 반환
## 패키지 관련
import image.io_file.imgread
image.io_file.imgread.pngread()
from image.io_file import imgread
imgread.pngread()
from image.io_file.imgread import pngread
pngread()
from image.io_file.imgread import *
pngread()
반응형