Posts Tagged ‘XML’
How to catch ‘ExpatError exception’ (handling)
ElementTree와 같은 패키지를 사용하여 XML를 파싱하는 경우,
XML 엘리먼트의 짝이 안맞는 등, 유효하지 않은 XML 구성이 탐지되면
ExpatError가 뜨는데,
# XML 연산
catch ExpatError, e:
# do something
하면,
NameError: global name ‘ExpatError’ is not defined라는 에러가 뜬다.
이를 해결하려면,
ExpatError를 catch하는 py 파일의 앞에, scope을 맞춰서
라고 넣어주자. 그러면, 문제 해결!!
”
While you are using XML packages such as ElementTree, you might want to handle
ExpatError which might be caused by invalid-format or missing tags and so on.
However, you will see another error message saying “NameError: global name ‘ExpatError’
is not defined”. What you only have to solve this problem is just add a line on the top of
your code.
That is,
from xml.parsers.expat import ExpatError
It’ll work, then.
queue의 push/pop 속도 비교
ㅁ Queue.Queue
1. push(‘a’) : 6.39s
2. push(‘a’) + pop() : 11.37s
ㅁ collections.dequeue
1. append(‘a’) : 0.13s
2. append(‘a’) + popleft() : 0.27s
ㅁ list
1. append(‘a’) : 0.15s
2. append(‘a’) + pop() : 0.40s
Queue를 쓰려면, dequeue를 활용하는 것이 좋을 것 같다.