if__name__ =="__main__":
현재 스크립트 프로그램을 최초로 시작한 파일인지 판단하는 작업이다.
import delete # delete 모듈을 가져옴
print('hi.py __name__:', __name__) # __name__ 변수 출력
#import하면 __name__에는 모듈의 이름이 저장됨.
hello 모듈 시작
hello.py __name__: delete #그래서 여기는 delete가 들어감
hello 모듈 끝
main.py __name__: __main__ #직접 실행한 파일은 __main__이 들어감
"""
1. hi 파일에서 실행
2. import된 delte 파일 가서 읽고 끝나면
3. hi 파일로 넘어와서 출력
"""
'Python' 카테고리의 다른 글
[Python] 데코레이터(Decorator) (0) | 2023.03.23 |
---|---|
[Python] 클로저(Closure) (0) | 2023.03.23 |
[Python] 클래스 self (0) | 2023.03.23 |
[Python] 클래스 생성자(init 함수) (0) | 2023.03.23 |
[Python] CSV(comma-separated values) 파일 (0) | 2023.03.22 |