Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109221
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Albert-Jan Roskam <sjeik_appie@hotmail.com> |
| Newsgroups | comp.lang.python |
| Subject | RE: re.search - Pattern matching review ( Apologies re sending) |
| Date | Sat, 28 May 2016 19:12:22 +0000 |
| Lines | 33 |
| Message-ID | <mailman.15.1464462809.1839.python-list@python.org> (permalink) |
| References | <CACT3xuXhA9U1Cwsw_OUW-Zfu96o-Bd9-OHFas80=M9etB0=bsw@mail.gmail.com> <DUB123-W24AEE854E04581EC90DDE283430@phx.gbl> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="windows-1256" |
| Content-Transfer-Encoding | base64 |
| X-Trace | news.uni-berlin.de Cav9AsaQIsekh7hCQ8rBGw03ds9vt6UyH7L6fRbqTBNg== |
| Return-Path | <sjeik_appie@hotmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'none:': 0.05; 'retrieved': 0.05; '"%s"': 0.09; 'cmd': 0.09; 'matched': 0.09; 'stdout': 0.09; 'python': 0.10; '2.7': 0.13; 'output': 0.13; 'def': 0.13; 'suggest': 0.15; '(pdb)': 0.16; '2016': 0.16; 'buggy': 0.16; 'e))': 0.16; 'ioerror,': 0.16; 'magic': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:sending': 0.16; 'try:': 0.18; '>': 0.18; 'to:2**1': 0.21; 'trying': 0.22; 'code.': 0.23; 'matching': 0.23; 'sat,': 0.23; 'import': 0.24; 'header:In-Reply- To:1': 0.24; 'linux': 0.26; 'skip:( 20': 0.28; 'looks': 0.29; 'url:mailman': 0.30; 'code': 0.30; 'date:': 0.31; 'url:python': 0.33; '+0530': 0.33; 'extract': 0.33; 'url:listinfo': 0.34; "skip:' 20": 0.34; 'except': 0.34; 'could': 0.35; 'false': 0.35; 'friends,': 0.35; 'subject:': 0.35; 'skip:i 20': 0.36; 'url:org': 0.36; 'lines': 0.36; 'email addr:python.org': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'skip:- 20': 0.39; 'from:': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'address': 0.61; 'email addr:gmail.com': 0.62; 'here': 0.66; 'email name:python-list': 0.67; 'charset:windows-1256': 0.67; 'dear': 0.67; 'sending)': 0.84; 'subject: ( ': 0.84; 'subject:review': 0.84 |
| X-TMN | [YD69hlqOBtdmTyDRiOUjdec0ik3UDEEQ] |
| X-Originating-Email | [sjeik_appie@hotmail.com] |
| Importance | Normal |
| In-Reply-To | <CACT3xuXhA9U1Cwsw_OUW-Zfu96o-Bd9-OHFas80=M9etB0=bsw@mail.gmail.com> |
| X-OriginalArrivalTime | 28 May 2016 19:12:22.0586 (UTC) FILETIME=[DCD499A0:01D1B914] |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.22 |
| 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 | <DUB123-W24AEE854E04581EC90DDE283430@phx.gbl> |
| X-Mailman-Original-References | <CACT3xuXhA9U1Cwsw_OUW-Zfu96o-Bd9-OHFas80=M9etB0=bsw@mail.gmail.com> |
| Xref | csiph.com comp.lang.python:109221 |
Show key headers only | View raw
> Date: Sat, 28 May 2016 23:48:16 +0530
> Subject: re.search - Pattern matching review ( Apologies re sending)
> From: ganesh1pal@gmail.com
> To: python-list@python.org
>
> Dear Python friends,
>
> I am on Python 2.7 and Linux . I am trying to extract the address
> "1,5,147456:8192" from the below stdout using re.search
>
> (Pdb) stdout
> 'linux-host-machine-1: Block Address for 1,5,27320320:8192 (block
> 1,5,147456:8192) --\nlinux-host-machine-1: magic
> 0xdeaff2fe mark_cookie 0x300000000000000a\n'
> (Pdb) type(stdout)
> <type 'str'>
>
> Here is the code I have come up with, this looks buggy please review
> the same and suggest any better ways to code.
>
> Could we use splitlines() or re.complie() etc , my intention is to
> match 1,5,147456:8192 and return the same.
>
>
> #Sample code
>
> import re
> import subprocess_run
>
> def get_block():
> try:
> cmd = "get_block_info -l"
> # stdout is the output retrieved by subprocess.Popen()
> stdout, stderr, exitcode = subprocess_run(cmd)
> search_pat = 'Block Address.* \(block (\d+),(\d+),(\d+):(\d+)'
> matched = re.search(search_pat, stdout)
> block = (int(matched.group(1)),
> int(matched.group(2)),
> int(matched.group(3)),
> int(matched.group(4)),
> )
Perhaps:map(int, re.search(search_pat, stdout).groups())
Or re.findall
> except IOError, e:
> logging.warning('Error reading lines from "%s" (%s).'
> % (cmd, e))
>
> if block is None:
> logging.error("block not found")
> return False
> logging.info("block not found")
> return block
>
> Regards,
>
> Ganesh
> --
> https://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
RE: re.search - Pattern matching review ( Apologies re sending) Albert-Jan Roskam <sjeik_appie@hotmail.com> - 2016-05-28 19:12 +0000
csiph-web