Python get rid of bytes b' '

后端 未结 6 1537
悲&欢浪女
悲&欢浪女 2021-02-18 17:24
import save

string = \"\"

with open(\"image.jpg\", \"rb\") as f:
    byte = f.read(1)
    while byte != b\"\":
        byte = f.read(1)
        print ((byte))
<         


        
6条回答
  •  日久生厌
    2021-02-18 17:57

    This is one way to get rid of the b'':

    import sys
    print(b)
    

    If you want to save the bytes later it's more efficient to read the entire file in one go rather than building a list, like this:

    with open('sample.jpg', mode='rb') as fh:
        content = fh.read()
        with open('out.jpg', mode='wb') as out:
            out.write(content)
    

提交回复
热议问题