I want to run df command on the specific directory from where the python file will be executed and format the output in dictionary format as: {'Mounted on': 'Available'}
import os
stream = os.popen('df -k')
output = stream.read()
output
When I run the code the output comes in the following format:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/lg_root
24489260 2533832 20693860 11% /
devtmpfs 2021940 0 2021940 0% /dev
tmpfs 2022896 0 2022896 0% /dev/shm
tmpfs 2022896 1544 2021352 1% /run
/dev/mapper/logs
2022896 0 2022896 0% /var/log
tmpfs 2022896 0 2022896 0% /tmp
The pattern of output in the rows is different. In 2 and 7 rows, the output is different from other rows. I tried split('\n'), strip(' ') but the output was inconsistent and incorrect. How to format the output in the expected way?