본문 바로가기

나름분류해서써보기173

XML을 처리 하는 파이썬 라이브러리중 ElementTree에 대해 알아보자.( xml 생성) XML을 처리 하는 파이썬 라이브러리중 ElementTree에 대해 알아보자. ( http://effbot.org/zone/element.htm ) ElementTree 모듈을 추가한다.from xml.etree.ElementTree import *Element 생성시, 직접 attribute를 추가note = Element("note") memo = Element("memo", date='20140202')SubElement는 태그명과 태그의 텍스트값을 한번에 설정할 수 있다. 태그에 어트리뷰트 추가할수 있다. note.attrib['time'] = '20140101' [root@master python]# cat sampleXml.py #coding=utf8from xml.etree.ElementTr.. 2015. 11. 10.
시스템 명령행 인자와 파일다루기 예제(간단한 메모장 만들기) 간단한 메모장 만들기 연습이다. https://wikidocs.net/36 에 나와있고, 여기서 말하능 기능은 다음과 같다. 옵션 -a는 추가 , 옵션 -v는 파일을 보여 주는 옵션이다. (+ 거기에 추가로) 작업하려는 메모파일이름도 사용자로 부터 입력받아서 처리하도록 구현해보자. 아래는 실행 화면이다. # python memo.py test.txt -a Enter note : hello world^^ Added !! # python memo.py test.txt -v Wed Oct 15 14:49:28 2014: hello world^^ main 함수에서는 sys.argv에 대한 validation 체크를 howto함수에서는 안내에 대한 처리를 fileRead는 파일을 read 하는 기능을 fileWr.. 2015. 11. 10.
파이썬 Queue - a aynchronized queue class https://docs.python.org/2/library/queue.htmlhttp://sarangyik.tistory.com/64The Queue module implements multi-producer, multi-consumer queues. It is especially useful in threaded programming when information must be exchanged safely between multiple threads. The Queue class in this module implements all the required locking semantics.Queue.putitem[, block[, timeout]]put_nowait(item)Queue.get[bloc.. 2015. 11. 10.
파이썬에서의 쓰레드 (http://noon.tistory.com/1171 블로그 글 중..) * 스레드와 함께 큐 사용 큐를 사용하는 방법을 우수 사례로 간주한다. 큐는 훨씬 더 다루기 쉽고, 스레드 프로그래밍을 더 안전하게 만든다. 단일 스레드 자원에 대한 모든 접근을 효과적으로 허용하며, 더 깔끔하고 읽기 쉬운 디자인 패턴을 허용하기 때문이다. 예제내용은, url을 가져와 페이지를 load 한후, 첫 512 바이트를 출력하는 프로그램으로, 스레드를 사용하지 않았을때와 스레드로 사용했을때의 수행시간을 비교해서 볼수 있다. 아래 스크립트는 threading.Thread 클래스를 상속받은 ThreadUrl 클래스로 구현한 예이다. (블로그 소스와 유사) [root@master python]# vim 2_testThread.p.. 2015. 11. 10.