Notice
Recent Posts
Recent Comments
Link
nathan_H
python - __name__ 본문
class Mutal:
def __init__(self):
self.now_state = "mutal"
self.hp = 100
self.attackt_rate = 10
@property
def state(self):
print("now state")
return self.now_state
@state.setter
def state(self, select, upgrade=["gardian", 'devaurer']):
print("upgrade complete")
self.now_state = upgrade[select]
print(__name___)
if __name__ == "__main__":
h1 = Mutal()
print(h1.state)
h1.state = 1
print(h1.state)
__main__
now state
mutal
upgrade complete
now state
devaurer
python에는 __name__이라는 것이
내장되어 있고 default로
어떠한 파일이든
__name__은 __main__으로 되어 있기 때문에
if __name__ == "__main__"이 참이기 때문에
위와 같이 실행이 된다.
이런 것을 하는 이유는
모듈에 있는 기능 객체, method만
가져와 실행을 하기 위해 조건 아래에
파일내 실행구문을 넣어
import시 파일내에 있는 기능만
가져와 사용 한다.
'Programming Laguage > Python' 카테고리의 다른 글
정규식 수업. (0) | 2019.06.03 |
---|---|
python - 모듈 수정 (0) | 2019.05.01 |
python - Module (0) | 2019.05.01 |
python - namedtuple (0) | 2019.04.30 |
python class - duck typing (0) | 2019.04.30 |
Comments