[PATCH] D71746: Fix the "TypeError: a bytes-like object is required, not 'str'" in exploded-graph-rewriter.py on Python 3.5+

germyrinn via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 17 04:27:46 PDT 2020


germyrinn added a comment.
Herald added a subscriber: Charusso.

Python makes a clear distinction between bytes and strings . Bytes objects contain raw data — a sequence of octets — whereas strings are Unicode sequences . Conversion between these two types is explicit: you encode a string to get bytes, specifying an encoding (which defaults to UTF-8); and you decode bytes to get a string. Clients of these functions should be aware that such conversions may fail, and should consider how failures are handled.

We can convert bytes to string <http://net-informations.com/python/iq/byte.htm> using bytes class decode() instance method, So you need to decode the bytes object to produce a string. In Python 3 , the default encoding is "utf-8" , so you can use directly:

  b"python byte to string".decode("utf-8")




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71746/new/

https://reviews.llvm.org/D71746





More information about the cfe-commits mailing list