Last active
July 11, 2017 09:06
-
-
Save ivlevdenis/327330326537713345abda2a0d5f5fc4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(venv) di-erz@worklap:~$ ipython | |
Python 3.6.1 (default, Apr 22 2017, 20:17:23) | |
Type 'copyright', 'credits' or 'license' for more information | |
IPython 6.0.0 -- An enhanced Interactive Python. Type '?' for help. | |
In [1]: import re | |
In [2]: lsblk = list(re.finditer( | |
...: r'NAME=\"(?P<name>[\w|\d]+?)\" SIZE=\"(?P<size>[\w|\d]+?)\" TYPE=\"(?P<type>[\w|\d]+?)\"', | |
...: 'NAME="sda" SIZE="20G" TYPE="disk"\nNAME="sda1" SIZE="19G" TYPE="part"\nNAME="sda2" SIZE="1K" TYPE="part"\nNAME="sda5" SIZE="1022M" TYPE="part"\nNAME="sr0" | |
...: SIZE="1024M" TYPE="rom"\n')) | |
In [3]: for blk in lsblk: | |
...: print(blk.groupdict()) | |
...: | |
{'name': 'sda', 'size': '20G', 'type': 'disk'} | |
{'name': 'sda1', 'size': '19G', 'type': 'part'} | |
{'name': 'sda2', 'size': '1K', 'type': 'part'} | |
{'name': 'sda5', 'size': '1022M', 'type': 'part'} | |
{'name': 'sr0', 'size': '1024M', 'type': 'rom'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment