python去掉空格和 b
直接看下面实例:
In [52]: output=subprocess.check_output(["head -c 16 /dev/urandom | od -An -t x | tr -d ' '"], shell=True) In [53]: print(output) b'3512c668547cd983cb48ccf05b0ccedf\n' In [67]: output.strip() Out[67]: b'3512c668547cd983cb48ccf05b0ccedf' In [72]: output.strip().strip('b') --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-72-d12ac1d7dec8> in <module> ----> 1 output.strip().strip('b') TypeError: a bytes-like object is required, not 'str' In [70]: str(output.strip()).strip('b') Out[70]: "'3512c668547cd983cb48ccf05b0ccedf'"