The logic of the for loop in the python return return value

the code is as follows:

self._os_bond_path = "/proc/net/bonding/*"

def __get_os_bonding(self):
    return list(set([b.split("/")[-1] for b in glob.glob(self._os_bond_path)]))
    

ask the expert to give us some advice on the logic and content of the value of this function. Thank you very much.

Mar.23,2021

 

first glob.glob (self._os_bond_path) this is a list of all files to see the usage of glob in detail

the list above in the

loop gets b and then split b to'/ 'cut out the last bit (which should be the file name and file type)

deduplicates all the resulting files by set and returns
by putting them in the list. The final result is all the deduplicated file names of / proc/net/bonding/ in this directory (all in the list)

Menu