Python Forum
Generate lists of devices and partitions from /proc/partitions?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generate lists of devices and partitions from /proc/partitions?
#1
Generate list of devices and partitions, which includes blocks and names, from /proc/partitions?

For example this...

# cat /proc/partitions
179 0 30976000 mmcblk0
179 1 262144 mmcblk0p1
179 2 30709760 mmcblk0p2
8 0 156290904 sda
8 1 156289880 sda1

Resulting in this...
Disks: [(30976000, mmcblk0), (156290904, sda)]
Partitions: [(262144, mmcblk0p1), (30709760, mmcblk0p2), (156289880, sda1)]
Reply
#2
Sounds like a homework assignment.

The trick is that /proc/partitions uses whitespace to look somewhat like a table. You cannot use split(' ') because that would give you something like this (based on running this code on my PC):
Output:
['8', '', '', '', '', '', '', '', '0', '', '', '39080664', 'sda'] ['8', '', '', '', '', '', '', '', '1', '', '', '', '', '524288', 'sda1'] ['8', '', '', '', '', '', '', '', '2', '', '', '38555335', 'sda2']
So you either need to remove the extra whitespace or find a way to treat multiple blanks as one. I think I remember there being a re.split() where you can specify a regex pattern. I would start looking there.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,832 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,387 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Best way to iterate through output to get the status of devices idkwhatimdoing 0 1,455 Apr-22-2020, 02:05 AM
Last Post: idkwhatimdoing
  How to make the script ignore down devices. wagnergt12 4 3,240 Apr-20-2020, 11:45 PM
Last Post: wagnergt12
  Where is usually located the python interpreter on android devices? anddontyoucomebacknomore 1 2,269 Jul-03-2019, 06:32 PM
Last Post: metulburr
  Generate unique random numbers from different lists Takeshio 5 3,803 May-24-2019, 07:29 PM
Last Post: ichabod801
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,294 Mar-20-2019, 08:01 PM
Last Post: stillsen
  Visiting invisible folders in /proc anddontyoucomebacknomore 0 1,582 Mar-18-2019, 02:05 AM
Last Post: anddontyoucomebacknomore
  Problems parsing /proc folder anddontyoucomebacknomore 2 2,577 Mar-06-2019, 09:16 PM
Last Post: DeaD_EyE
  execute a SQL stored proc within PYTHON PYTHONDUDE 3 9,515 Mar-21-2018, 04:15 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020