python - Unble to use strip method -
here's input:
vendor: seagate product: st914602ssun146g revision: 0603 serial no: 080394enwq size: 146.81gb <146810536448 bytes>
my code:
iostat_cmd = client.executecmd('iostat -en '+disk+'|egrep \'vendor|size\'') vendor = re.search(r'vendor:(.*)product:',iostat_cmd) vendor = str(vendor.groups()).strip() product = re.search(r'product:(.*)revision:',iostat_cmd) product = str(product.groups()).strip() revision = re.search(r'revision:(.*)serial no:',iostat_cmd) revision = str(revision.groups()).strip() serial = re.search(r'serial no:(.*)',iostat_cmd) serial = str(serial.groups()).strip() size = re.search(r'size:(.*)<.*>',iostat_cmd) size = str(size.groups()).strip()
the problem is, it's not converting result of groups() string, why strip() doesn't anything. want remove leading , trailing whitespaces. please not suggest using replace because of match groups can made multiple words (for example, product name can virtual disk) , take account fact use of whitespaces/delimiters in iostat command output arbitrary, why i'm going through trouble in first place.
here's happens:
jvm 2 | <type 'org.python.modules.sre.matchobject'> jvm 2 | <type 'str'> jvm 2 | (u' seagate ',) jvm 2 | (u' st914602ssun146g ',) jvm 2 | (u' 0603 ',) jvm 2 | (u' 080394ec41 \r',) jvm 2 | (u' 146.81gb ',) jvm 2 | (u' seagate ',)(u' st914602ssun146g ',)(u' 0603 ',)(u' 080394ec41 \r',)(u' 146.81gb ',)
when use .groups()
on match object tuple contents of captured groups regex.
to contents of first capture use .group(1)
instead.
Comments
Post a Comment