Coming from this link: Splitlines in Python a table with empty spaces
It works well but there is a problem when the size of the columns change:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
init 1 root cwd unknown /proc/1/cwd (readlink: Permission denied)
init 1 root rtd unknown /proc/1/root
And the problem starts in col Device or Size/OFF but maybe in other situations could happen in all columns.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
init 1 root cwd DIR 8,1 4096 2 /
init 1 root rtd DIR 8,1 4096 2 /
init 1 root txt REG 8,1 36992 139325 /sbin/init
init 1 root mem REG 8,1 14696 190970 /lib/libdl-2.11.3.so
init 1 root mem REG 8,1 1437064 190958 /lib/libc-2.11.3.so
python 30077 carlos 1u CHR 1,3 0t0 700 /dev/null
Checking always is the same in the first row, the first column starts in C of COMMAND, second ends in D of PID, the four col. in D +1 of FD.... is there any way to count the number of spaces in the first row to use them to fill this code to parse the other rows?
# note: variable-length NAME field at the end intentionally omitted
base_format = '8s 1x 6s 1x 10s 1x 4s 1x 9s 1x 6s 1x 9s 1x 6s 1x'
base_format_size = struct.calcsize(base_format)
Any ideas how to solve the problem?