본문 바로가기

Python4

Python 에서 xml 사용하기. element tree 를 사용.. Python 에서 xml 사용하기. element tree 를 사용.. 파이썬 홈페이지 http://www.python.org/ element tree 페이지. (python 3.2) http://docs.python.org/py3k/library/xml.etree.elementtree.html ----------------------------------- xml 파일 내용... ----------------------------------- #-*- coding: utf-8 -*- import os from xml.etree.ElementTree import ElementTree tree = ElementTree() tree.parse('test.xml') ### root root = tree.get.. 2011. 8. 19.
Python 삼항연산자 사용방법.. C 스타일 var = condition ? true : false; Python 스타일 ( 2.5 버전 이상부터 가능하다고 한다. 확인해 보진 않았음. ) var = True if condition else False condition이 참이면 앞의 변수사용 condition이 거짓이면 뒤의 변수사용 C 스타일과 순서가 다르고 기호가 아닌 조건문이 들어간다. C : 1 ? 2 : 3 Python : 2 if 1 else 3 2011. 8. 18.
python 파일 언어 인코딩 설정하기 출처 : http://www.python.org/dev/peps/pep-0263/ 파일별 인코딩 설정이 가능하고 첫째 혹은 둘째 라인에 설정 하지 않으면 동작하지 않는다. 방법 1 #!/usr/bin/python # -*- coding: latin-1 -*- import os, sys ... #!/usr/bin/python # -*- coding: iso-8859-15 -*- import os, sys ... #!/usr/bin/python # -*- coding: ascii -*- import os, sys ... 방법2 # This Python file uses the following encoding: utf-8 방법3 #!/usr/local/bin/python # coding: latin-1 im.. 2010. 11. 24.
python 디렉토리내부 파일리스트 가져오기 특정 패턴을 적용해서 ( *.* ) 디렉토리 내부에서 파일 리스트를 뽑아주는 함수. ########################################################################## #-*- coding: cp949 -*- import os import glob def searchPatternIncludeSub(dir,patternStr): # 우선 지금 폴더의 패턴 검색 해서 저장. retlist = glob.glob(os.path.join(dir, patternStr)) # 하위 디렉토리 검색 findlist = os.listdir(dir) for f in findlist: next = os.path.join(dir, f) if os.path.isdir(next):.. 2010. 11. 24.