0
file = open("images.jpeg", "rb")

c = file.read(512)
print(type(c))
print(c)

file.close()

c is a str object. Shouldn't it be a bytes object? According to doc, it should be!

In Python 3.2, it is really a bytes object. What happened in Python2.7?

Platform: Kubuntu 12.04 64-bit

4
  • What problem is this causing you? Commented Sep 30, 2012 at 13:48
  • What is the question exactly? Commented Sep 30, 2012 at 13:56
  • I want to analyse image file format, get the file header and raw data. How to operate on str object? Commented Sep 30, 2012 at 14:01
  • 1
    Use the struct module to "Interpret strings as packed binary data". Commented Sep 30, 2012 at 16:33

1 Answer 1

3

bytes is an alias for str in Python 2.7

Sign up to request clarification or add additional context in comments.

1 Comment

Maybe the OP should convert the bytes (str) read in into a bytearray.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.