This repository was archived by the owner on Dec 1, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimport&as.py
More file actions
Latest commit
47 lines (34 loc) · 1.28 KB
/
Copy pathimport&as.py
File metadata and controls
47 lines (34 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Import와 AS
# Import를 작성할 때는 한 줄에 하나씩, 알파벳 순서로 적는 것이 협엽에 좋다.
# 그리고 모듈, 써드파티, 만든 패키지, 로컬 패키지들은 서로 한 칸씩 띄워 구분하는게 좋다.
# 패키지만 가져오기
# import package.tools.utils
# r = package.utils.say_twice('hello')
# 패키지의 모듈만 가져오기
# from package.tools import utils
# r = utils.say_twice('hello')
# 패키지의 모듈 안 함수만 가져오기(추천은 안함)
# from package.tools.utils import say_twice
# r = say_twice('hello')
# 패키지의 모듈을 가져와서 별칭을 정하기(추천은 안함)
# from package.tools import utils as u
# r = u.say_twice('hello')
# print(r)
# from package.talk import human
# r = human.sing()
# 해당 모듈은 절대경로로 함수를 참조함
# r = human.cry()
# print(r)
# __init__파일에서 all 항목을 넣어 애스터리스크를 사용 가능했다.(추천은 안함)
# from package.talk import *
# print(animal.sing())
# print(animal.cry())
# print(human.sing())
# print(human.cry())
# 옛 버전과 새 버전 간의 오류를 해결하기 위한 예외처리
# try:
# from package import utils
# except:
# from package.tools import utils
# r = utils.say_twice('word')
# print(r)