Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109253
| From | Ganesh Pal <ganesh1pal@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | python parsing suggestion |
| Date | 2016-05-30 13:04 +0530 |
| Message-ID | <mailman.36.1464593664.1839.python-list@python.org> (permalink) |
| References | <CACT3xuV3Rdku_8GOjjLNc6iSChtYBkkQaJrhiWTfk6T4Gvvefw@mail.gmail.com> |
Hi ,
Trying to extract the '1,1,114688:8192' pattern form the below output.
pdb>stdout:
'3aae5d0-1: Parent Block for 1,1,19169280:8192 (block 1,1,114688:8192)
--\n3aae5d0-1:
magic 0xdeaff2fe mark_cookie
0x0000000000000000\ngpal-3aae5d0-1: super.status
3 super.cookie 390781895\ngpal-3aae5d0-1:
cg_xth 0
I am on python 2.7 and Linux the below code sample is working fine (
please raise the error if u find it will help me improve this
codebetter)
def check_block(block):
"""
Trying to extract the '1,1,114688:8192' pattern from the above output.
"""
logging.info('Determining history block for block %s' % (block))
parent_block = None
node_id = block.split(",")[0]
cmd = ("get_block_info -l" % (node_id, block))
logging.info(cmd)
stdout, stderr, exitcode = run(cmd)
try:
parent_block = stdout.strip().split('\n')[0].split()[6][:-1]
except (IndexError, ValueError):
logging.error('Error determining history block for %s.' % (block))
return False
if re.search(r'(\d+),(\d+),(\d+):(\d+)', parent_block):
logging.info('Found history block %s for data block %s' %
(parent_block, block))
return parent_block
return False
Need suggestion for the below 3 points:
1. Is parsing with stdout.strip().split('\n')[0].split()[6][:-1]
sufficient do I need to add extra check ? it looks fine for me though.
2. Better ways to achieve the same output we need to parse is a string
3. Is re.search(r'(\d+),(\d+),(\d+):(\d+)', parent_block) needed ? I
added as an extra check ,any ideas on the same
Regards,
Ganesh
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
python parsing suggestion Ganesh Pal <ganesh1pal@gmail.com> - 2016-05-30 13:04 +0530
csiph-web