xml.etree.ElementTree if element does not exist?

Ombongi Moraa Fe moraa.lovetakes2 at gmail.com
Mon Apr 29 06:26:51 EDT 2013


Good Afternoon,

Among other elements values that my script finds is value for sepid

sepid = content.find(".//{http://www.huawei.com.cn/schema/common/v2_1}sepid
").text


however, if i pass xml data that DOES NOT contain sepid element, i get an
error:

Traceback (most recent call last):
  File "/usr/local/bin/receive.py", line 21, in <module>
    sepid = content.find(".//{
http://www.huawei.com.cn/schema/common/v2_1}sepid").text
AttributeError: 'NoneType' object has no attribute 'text'


some messages i receive will have the sepid parameter, other will not have
this parameter. How can i cater for this? kinda like an if .. else
implementation for xml.etree.ElementTree  ?



Thanks in advance.

Saludos

Ombongi Moraa Faith
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130429/7386758a/attachment.html>


More information about the Python-list mailing list