python去掉空格和 b

python

直接看下面实例:

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'"

以上是 python去掉空格和 b 的全部内容, 来源链接: utcz.com/z/388451.html

回到顶部