def _convert_mode(mode: int): if not 0 <= mode <= 0o777: raise RuntimeError res = '' for v in range(0, 9): if mode >> v & 1: match v % 3: case 0: res = 'x' + res case 1: res = 'w' + res case 2: res = 'r' + res else: res = '-' + res return res print(_convert_mode(0o757)) mode_list = dict(zip(range(9), list('rwx') * 3)) def _convert_mode(mode: int): if not 0 <= mode <= 0o777: raise ValueError res = '' # 8 -> 0, 7 -> 1 => v + x = 8 for v in range(8, -1, -1): if mode >> v & 1: res += mode_list[8 - v] else: res += '-' return res print(_convert_mode(0o577))
标签:case,convert,Python,res,list,int,mode From: https://www.cnblogs.com/dissipate/p/16875763.html