I have this ugly piece of code that runs ethtool then parses the output (
Lilex is just a subprocess of static class encapsulation and is not relevant to the question. I'm looking for suggestions to shorten the handling of the strings.
bash_command = "/sbin/ethtool -P " + identifier output = Lilex.execute_command(bash_command) mac_address = str(output) mac_address = mac_address.replace("Permanent address: ", "") mac_address = mac_address.replace("\n", "") mac_address = mac_address.replace("'", "") mac_address = mac_address(1:).strip()
This is an example of output produced by
Permanent address: 12:af:37:d0:a9:c8
I'm not sure why I replace single quotes with anything, but I'm sure I've already seen the single quotes at the command output, so this part has to stay.
An alternative suggestion (which is actually not very different):
mac_address = mac_address .split(":")(1) .replace("\n","") .replace("'","") .strip()