Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44496
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <moraa.lovetakes2@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'subject:not': 0.03; 'else:': 0.03; 'tree': 0.05; '21,': 0.07; 'attribute': 0.07; 'element': 0.07; 'error:': 0.07; 'none:': 0.07; 'received:209.85.219': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'element,': 0.16; 'parameter.': 0.16; 'wrote:': 0.18; 'stefan': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'this?': 0.23; 'skip:e 30': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'pass': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'xml': 0.29; 'returned': 0.30; 'message-id:@mail.gmail.com': 0.30; 'saludos': 0.31; 'file': 0.32; 'skip:c 30': 0.32; 'up.': 0.33; 'worked': 0.33; '(most': 0.33; 'skip:& 30': 0.33; 'received:209.85': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'subject:?': 0.36; 'received:209': 0.37; 'skip:& 10': 0.38; 'recent': 0.39; 'does': 0.39; 'how': 0.40; 'simply': 0.61; 'receive': 0.70; 'cater': 0.84; 'faith': 0.91; 'url:cn': 0.93; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=VYFrPye5B+7C2fpo+bikTbr5zjPOUSxoRwZc4OVDfv0=; b=hYbFEvbpIaWhqMGfcZIU8fuRfqj1yhX9ZzNbNaSsAjqc1p3R2mi69VUdmBpvpkz6oW CzGNmLskuekxPg1tAMGwAp39SPj3Ql5frJz/0qIu2Ta2JsR7CpjFFaxe+4s0jsBPhPnh 60dj9Mzjjqm5H2EgRGetJyFxCoWm1U3D5r/HxorSpnQF15cNW8ohZS3UBdkORjTuueux svymlZNgIMQx5tgnSSu2jiA7Nkz8p5i0EVpcpYy5TyX6DXaVGxqnwP0HStmETM2vsJZC YTpdbe2Qs6Y/ry59/g8f2Y1HVh1jaEa8ijnPTvdCUFOnLE4/G2bqwmoNzVS94f/xlgHk GWWA== |
| X-Received | by 10.182.219.136 with SMTP id po8mr8394700obc.75.1367236249025; Mon, 29 Apr 2013 04:50:49 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <556FF090-DABC-4A90-800F-6E3D81B6C80F@vectorfabrics.com> |
| References | <CAM6w3non8j1FdKWwENH1GabCE4n-9muDfQKQURsLn9JLFGWtAw@mail.gmail.com> <556FF090-DABC-4A90-800F-6E3D81B6C80F@vectorfabrics.com> |
| From | Ombongi Moraa Fe <moraa.lovetakes2@gmail.com> |
| Date | Mon, 29 Apr 2013 14:50:08 +0300 |
| Subject | Re: xml.etree.ElementTree if element does not exist? |
| To | Stefan Holdermans <stefan@vectorfabrics.com> |
| Content-Type | multipart/alternative; boundary=089e0153853af2837804db7e7e8b |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1152.1367236624.3114.python-list@python.org> (permalink) |
| Lines | 118 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1367236624 news.xs4all.nl 15889 [2001:888:2000:d::a6]:54154 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:44496 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Hi Stefan, Group
Thanks for the thumbs up.
Worked perfectly.
Saludos
Ombongi Moraa Faith
On 29 April 2013 14:22, Stefan Holdermans <stefan@vectorfabrics.com> wrote:
> Ombongi,
>
> > 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 ?
>
> What about simply testing whether the value returned by find is None? For
> example:
>
> $ cat test.py
> from xml.etree import ElementTree
>
> myTree = ElementTree.fromstring('<test />')
> myElement = myTree.find('orange')
>
> if myElement is None:
> print 'tree does not contain a child element "orange"'
> else:
> print myElement.text
>
>
> $ python test.py
> tree does not contain a child element "orange"
>
> HTH,
>
> Stefan
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: xml.etree.ElementTree if element does not exist? Ombongi Moraa Fe <moraa.lovetakes2@gmail.com> - 2013-04-29 14:50 +0300
csiph-web