Skip to content
Discussion options

You must be logged in to vote

The .mpy file format is a binary file format, so it really only makes sense to open it using the binary ('rb') option. Otherwise, it opens it as a text file and decodes the contents as a UTF-8 string object (which could actually cause an error if the file contains invalid UTF-8 sequences).

When opened as a binary file, Python reads the contents of the file as a bytes object instead of a string object. The way Python prints a bytes object looks very much like a string - there is just a b before the opening ".

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@kjm1102
Comment options

@dlech
Comment options

@kjm1102
Comment options

Answer selected by robert-hh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants