Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107600

RE: delete from pattern to pattern if it contains match

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Joaquin Alzola <Joaquin.Alzola@lebara.com>
Newsgroups comp.lang.python
Subject RE: delete from pattern to pattern if it contains match
Date Mon, 25 Apr 2016 10:19:56 +0000
Lines 75
Message-ID <mailman.71.1461585209.32212.python-list@python.org> (permalink)
References <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <lf5fuufqe81.fsf@ling.helsinki.fi> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <nfcqjs$guu$1@ger.gmane.org> <mailman.11.1461317067.2861.python-list@python.org> <lf57ffpdhl5.fsf@ling.helsinki.fi> <ee696bf4-706f-4113-bb91-d231ebf47b05@googlegroups.com> <lf5d1pew42b.fsf@ling.helsinki.fi> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> <nfkql5$gli$1@ger.gmane.org> <HE1PR07MB135650146927B98CE4240AEBF0620@HE1PR07MB1356.eurprd07.prod.outlook.com>
Mime-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de rttpw8Ktx3XLVXH8YLXg7gJxVLSMoPfubmo2dHnFciXQ==
Return-Path <Joaquin.Alzola@lebara.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.025
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'root': 0.04; 'skip:e 50': 0.05; 'expected.': 0.09; 'message-----': 0.15; '2016': 0.16; 'doesnt': 0.16; 'elem': 0.16; 'executed.': 0.16; 'privilege.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:[ 60': 0.16; 'to:addr:web.de': 0.16; 'wrote:': 0.16; 'tree': 0.18; 'to:name:python-list@python.org': 0.20; 'to:2**1': 0.21; 'xmlns=""': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'specify': 0.27; 'skip:( 20': 0.28; 'does,': 0.29; 'code:': 0.29; 'print': 0.30; 'url:mailman': 0.30; 'code': 0.30; 'probably': 0.31; 'skip:s 30': 0.31; 'statement': 0.32; 'url:python': 0.33; '"")': 0.33; 'skip:- 10': 0.34; 'url:listinfo': 0.34; 'sent:': 0.35; 'could': 0.35; 'subject:': 0.35; 'but': 0.36; 'url:org': 0.36; 'email addr:python.org': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'charset:us-ascii': 0.37; 'delete': 0.38; 'skip:s 40': 0.38; 'subject:from': 0.39; 'from:': 0.39; 'skip:e 20': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'some': 0.40; 'email addr:gmail.com': 0.62; 'contact': 0.66; 'python-list': 0.66; 'reuse': 0.66; 'here': 0.66; 'email name :python-list': 0.67; 'subject': 0.70; 'finally': 0.70; 'disclose': 0.71; 'subscribers': 0.72; 'otten': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=lebara.onmicrosoft.com; s=selector1-lebara-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=JsQlBb4T9SHv+6Ua8TpzQAPRpsSsCJx0MfUzUA2o+Jw=; b=Kd5d20WsZGz6orebS7wh8AOaEIdCF1Hh1bdWCMdoGtXgfuEA1y9+4q7ihekfclCef6FHYxik7SXLA/pDauBct7p8MTmXyfJV9kShYE+s+I+9yra/yEHdQZjI2t62kkSKeWLmCAmEyFeLk+a0f7Vpw4z2GFaZOzBee2LWioDrwmI=
Thread-Topic delete from pattern to pattern if it contains match
Thread-Index AQHRntuRROlwol0+U02RUJfmekSea5+aeZFQ
In-Reply-To <nfkql5$gli$1@ger.gmane.org>
Accept-Language en-GB, en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
authentication-results web.de; dkim=none (message not signed) header.d=none;web.de; dmarc=none action=none header.from=lebara.com;
x-originating-ip [212.161.49.106]
x-ms-office365-filtering-correlation-id a9b64e4e-8df6-481e-545f-08d36cf32652
x-microsoft-exchange-diagnostics 1; HE1PR07MB1356; 5:knRJGRkn4JdB3Mz4scUa/pDq9Jva/GtVs6ALtpVXcxXIV8+MZWDRRPodKsLO+ajNXUd56HFN8qnh6ImJHYEs2IlybBw9PNaIyjSA4OORkAE2L3PFmdKewRBVk54jkXBNzaYVOJM7emh3qYxLGO9HIg==; 24:Mvx+WwcawwOldyYX2ZNWfGUfq17EmG2qWnDaX2aRqB1osm/Z9UqXXJLNT871FiVl5joAon5Jp+sNM7IY7aYgv4AHip/brUc7S45Tb6cnVzk=; 7:f/txcPAhOSRsb5vDtFsOpOUFpj6pDGMrN18Gbdvrt/sLfH/2qCd8tGr+7MA5+8fBt4DfCOxQReAtV+NWEydXaZWrGvc2oj16f0rDBY/TCGDb/RSuKqy3MSy7+cdd4KUHoks5aMKBqMXeKZSkWQt0ks56xrK4tUhBm9LHBqbuCn1O7O4tEyRBXWCbQgqoYEUh
x-microsoft-antispam UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR07MB1356;
x-microsoft-antispam-prvs <HE1PR07MB135623B0B41470C482DE34E4F0620@HE1PR07MB1356.eurprd07.prod.outlook.com>
x-exchange-antispam-report-test UriScan:;
x-exchange-antispam-report-cfa-test BCL:0; PCL:0; RULEID:(9101521062)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001); SRVR:HE1PR07MB1356; BCL:0; PCL:0; RULEID:; SRVR:HE1PR07MB1356;
x-forefront-prvs 0923977CCA
x-forefront-antispam-report SFV:NSPM; SFS:(10019020)(6009001)(24454002)(13464003)(19580395003)(5002640100001)(19580405001)(76176999)(5001770100001)(50986999)(189998001)(5004730100002)(5003600100002)(15975445007)(2950100001)(54356999)(1220700001)(9686002)(77096005)(2900100001)(81166005)(1096002)(1720100001)(33656002)(6116002)(106116001)(87936001)(10400500002)(2906002)(107886002)(3660700001)(586003)(86362001)(93886004)(122556002)(3846002)(2501003)(102836003)(74316001)(76576001)(92566002)(11100500001)(5008740100001)(66066001)(3280700002); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR07MB1356; H:HE1PR07MB1356.eurprd07.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en;
spamdiagnosticoutput 1:23
spamdiagnosticmetadata NSPM
X-OriginatorOrg lebara.com
X-MS-Exchange-CrossTenant-originalarrivaltime 25 Apr 2016 10:19:56.4060 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader Hosted
X-MS-Exchange-CrossTenant-id d7093539-83cd-4991-b1b3-aacef74cf097
X-MS-Exchange-Transport-CrossTenantHeadersStamped HE1PR07MB1356
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <HE1PR07MB135650146927B98CE4240AEBF0620@HE1PR07MB1356.eurprd07.prod.outlook.com>
X-Mailman-Original-References <20c0b0fe-136b-4b01-b004-c55c6d47b299@googlegroups.com> <91432d7b-7233-4504-a725-22bc81637ea3@googlegroups.com> <lf5fuufqe81.fsf@ling.helsinki.fi> <991c5867-27d1-4e75-aa52-a7d47e626b74@googlegroups.com> <nfcqjs$guu$1@ger.gmane.org> <mailman.11.1461317067.2861.python-list@python.org> <lf57ffpdhl5.fsf@ling.helsinki.fi> <ee696bf4-706f-4113-bb91-d231ebf47b05@googlegroups.com> <lf5d1pew42b.fsf@ling.helsinki.fi> <8001ac2b-c883-4ca1-a163-d118cc82295b@googlegroups.com> <nfkql5$gli$1@ger.gmane.org>
Xref csiph.com comp.lang.python:107600

Show key headers only | View raw


I put some code I did before for the xmlns:

                              xml_root = ET.ElementTree(ET.fromstring(xml_decoded)).getroot()
                              for elem in xml_root.getiterator():
                                             if('{http://request.messagepush.interfaces.comviva.com/xsd}shortCode'==elem.tag):
                                                            shortCode = (elem.text).rstrip()
                                             if('{http://request.messagepush.interfaces.comviva.com/xsd}text'==elem.tag):
                                                            send_text = (elem.text).rstrip()
                                             if('{http://request.messagepush.interfaces.comviva.com/xsd}item'==elem.tag):
                                                            subscribers = (elem.text).rstrip()
                              result_sms = send_sms(subscribers,shortCode,send_text)

Reuse it.

-----Original Message-----
From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com@python.org] On Behalf Of Peter Otten
Sent: 25 April 2016 11:14
To: python-list@python.org
Subject: Re: delete from pattern to pattern if it contains match

harirammanohar@gmail.com wrote:

> Here is the code:

Finally ;)

> import xml.etree.ElementTree as ET
> ET.register_namespace("", "http://xmlns.jcp.org/xml/ns/javaee")

I don't know what this does, but probably not what you expected.

> tree = ET.parse('sample.xml')
> root = tree.getroot()
>
> for servlet in root.findall('servlet'):
>         servletname = servlet.find('servlet-name').text

I think you have to specify the namespace:

for servlet in root.findall('{http://xmlns.jcp.org/xml/ns/javaee}servlet'):
    servletname = servlet.find(
        '{http://xmlns.jcp.org/xml/ns/javaee}servlet-name').text

>         if servletname == "controller":

You could have added a print statement to verify that the line below is executed.

>                 root.remove(servlet)
>
> tree.write('output.xml')
>
> This will work if <web-app> </web-app> doesnt have below...
>
> xmlns="http://xmlns.jcp.org/xml/ns/javaee"
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
>                       http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"



--
https://mail.python.org/mailman/listinfo/python-list
This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-18 00:07 -0700
  RE: delete from pattern to pattern if it contains match Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-04-18 07:49 +0000
    Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-18 01:52 -0700
    Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-18 21:01 -0700
  Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-21 03:17 -0700
    Re: delete from pattern to pattern if it contains match Peter Otten <__peter__@web.de> - 2016-04-21 13:24 +0200
      Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-22 02:00 -0700
        Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-22 02:14 -0700
          Re: delete from pattern to pattern if it contains match Peter Otten <__peter__@web.de> - 2016-04-22 11:50 +0200
            Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-24 23:24 -0700
    Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-21 16:32 +0300
      Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-22 01:59 -0700
        Re: delete from pattern to pattern if it contains match Peter Otten <__peter__@web.de> - 2016-04-22 11:24 +0200
          Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-22 14:10 +0300
            Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-24 23:29 -0700
              Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 10:17 +0300
                Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-25 02:49 -0700
                Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-25 02:53 -0700
                Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 13:37 +0300
                Re: delete from pattern to pattern if it contains match Peter Otten <__peter__@web.de> - 2016-04-25 12:13 +0200
                Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 13:39 +0300
                Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-25 04:02 -0700
                Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 14:28 +0300
                Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-25 04:40 -0700
                Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 15:00 +0300
                Re: delete from pattern to pattern if it contains match Peter Otten <__peter__@web.de> - 2016-04-25 14:33 +0200
                Re: delete from pattern to pattern if it contains match harirammanohar@gmail.com - 2016-04-26 03:31 -0700
                Re: delete from pattern to pattern if it contains match Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-25 13:24 +0300
                RE: delete from pattern to pattern if it contains match Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-04-25 10:19 +0000

csiph-web