_대문 | 방명록 | 최근글 | 홈피소개 | 주인놈 |
FrontPage › Python-Tip1
|
|
[edit]
1 working directory 변경 #import os print os.getcwd() #현재 working directory 알아내기 os.chdir('d:\pydata') [edit]
2 변수의 데이터형 알아내기 #>>> a = 'dynamic' >>> x = type(a) >>> x <type 'str'> >>> x.__name__ 'str' >>> 비교시에 다음과 같이 하는 것이 좋을 듯..
>>> isinstance('aaa', str) True >>> isinstance(123, int) True [edit]
3 동적 실행 #동적 실행의 단위
>>> a = 1 >>> a = eval('a+1') >>> a 2 statment
>>> exec 'a = a + 1' >>> a 3 동적 실행은 과도한 컴파일을 유발할 수 있다. 그래서 컴파일 된 것으로 실행할 수 있다. expression이나 statment 모두 컴파일해서 사용할 수 있다.
>>> a = 1 >>> compiled_code = compile('a + 1', '<string>', 'eval') >>> a = 1 >>> for i in range(5): ... a = eval(compiled_code) ... >>> a 6compile() 함수의 3번째 인자에서..
|
남보다 앞서는 사람은 자격증이 있는 사람이 아니라 관심이 있는 사람이다. |