Decode the bytes object to produce a string:
>>> b"abcde".decode("utf-8")
'abcde'
The above example assumes that the bytes object is in UTF-8, because it is a common encoding. However, you should use the encoding your data is actually in!
Top answer 1 of 16
5878
Decode the bytes object to produce a string:
>>> b"abcde".decode("utf-8")
'abcde'
The above example assumes that the bytes object is in UTF-8, because it is a common encoding. However, you should use the encoding your data is actually in!
2 of 16
430
Decode the byte string and turn it in to a character (Unicode) string.
Python 3:
encoding = 'utf-8'
b'hello'.decode(encoding)
or
str(b'hello', encoding)
Python 2:
encoding = 'utf-8'
'hello'.decode(encoding)
or
unicode('hello', encoding)
How to convert bytes to string in python?
Try this: line = ser.readline().strip() values = line.decode('ascii').split(',') a, b, c = [int(s) for s in values] The call to .strip() removes the trailing newline. The call .decode('ascii') converts the raw bytes to a string. .split(',') splits the string on commas. Finally the call [int(s) for s in value] is called a list comprehension, and produces a list of integers. More on reddit.com
Converting bytes to string to bytes
How can I convert bytes to string to bytes back? Here’s what I’m trying: from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import padding message = b"A message I want to sign" signature = private_key.sign( message, padding.PSS( mgf=padding... More on discuss.python.org
How To Convert Bytes To A String - Different Methods Explained
This article confuses more than it explains, I don't consider it very helpful to someone trying to understand the distinction between a character string and a byte string. You may want to look elsewhere for a good explanation. More on reddit.com
How do I convert a string to bytes?
Or use the bytes() builtin function . An example: x = "abc☺xyz" print(x) y = bytes(x, encoding="utf-8") print(y) More on reddit.com
Videos
12:15
Convert Bytes to String [Python] - YouTube
04:03
How to convert bytes into strings in Python - YouTube
02:29
Python Program #89 - Convert Bytes to a String in Python - YouTube
01:27
How to convert bytes to a string in Python - YouTube
01:04
How to Convert Bytes to String in Python 3: A Complete Guide - YouTube
python how to convert bytes to string
DataCamp
datacamp.com › tutorial › bytes-to-string-python
How to Convert Bytes to String in Python | DataCamp
June 12, 2024 - To convert bytes to strings in Python, we can use the .decode() method, specifying the appropriate encoding.
DigitalOcean
digitalocean.com › community › tutorials › python-string-encode-decode
Python String Encode and Decode: Complete Guide | DigitalOcean
August 3, 2022 - Python string encode() function is used to encode the string using the provided encoding. This function returns the bytes object. If we don’t provide encoding, “utf-8” encoding is used as default. Python bytes decode() function is used to convert bytes to string object.
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-bytes-to-string-in-python
How to Convert Bytes to String in Python ? - GeeksforGeeks
The str() function of Python returns the string version of the object. ... It’s a useful alternative, especially when you're not calling it on a byte object directly. The codecs module provides an alternative way to decode bytes, especially useful when dealing with different encodings.
Published July 23, 2025
Reddit
reddit.com › r/python › how to convert bytes to string in python?
r/Python on Reddit: How to convert bytes to string in python?
February 8, 2016 -
i am stuck in python programming. i read a line from the serial port
line=ser.readline() print(line)
when the above code is executed i get like
b'-83,-156,-205\r\n'
but i want only values like a=-83,b=-156,c=-205. how to extract these values/ how to get these values?
Top answer 1 of 3
3
Try this: line = ser.readline().strip() values = line.decode('ascii').split(',') a, b, c = [int(s) for s in values] The call to .strip() removes the trailing newline. The call .decode('ascii') converts the raw bytes to a string. .split(',') splits the string on commas. Finally the call [int(s) for s in value] is called a list comprehension, and produces a list of integers.
2 of 3
2
On python 3: line = ser.readline().decode() Also you can specify the character encoding: line = ser.readline().decode("ascii") line = ser.readline().decode("utf-8")
Mimo
mimo.org › glossary › python › string-decode
Python string decode(): Syntax, Usage, and Examples
Use decode() in Python to convert bytes to readable strings using the correct encoding. It's essential for processing files, APIs, or web content.
Python.org
discuss.python.org › python help
Converting bytes to string to bytes - Python Help - Discussions on Python.org
October 28, 2021 - How can I convert bytes to string to bytes back? Here’s what I’m trying: from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import padding message = b"A message I want to sign" signature = private_key.sign( message, padding.PSS( mgf=padding.MGF1(hashes.SHA256()), salt_length=padding.PSS.MAX_LENGTH ), hashes.SHA256() ) converting the signature using base64 encode and decode methods to string.
Stack Abuse
stackabuse.com › convert-bytes-to-string-in-python
Convert Bytes to String in Python
November 27, 2020 - In this tutorial, we'll go over examples of how to convert bytes to a string in Python 2 and 3. We'll use the decode() function, str() function as well as the codecs module.
Net Informations
net-informations.com › python › iq › byte.htm
How to convert bytes to string in Python?
The most common method for converting bytes to a string in Python is to use the decode() method.
Programiz
programiz.com › python-programming › examples › bytes-to-string
Python Program to Convert Bytes to a String
To understand this example, you should have the knowledge of the following Python programming topics: ... Using decode(), you can convert bytes into string. Here, we have used utf-8 for decoding.
iO Flood
ioflood.com › blog › python-bytes-to-string
Python Bytes to String Conversion Guide (With Examples)
December 11, 2023 - To manage this, you can specify an error handling scheme as a second argument to the decode method, such as ‘ignore’ or ‘replace’. byte_object = b'Hello, Python!\x80' string_object = byte_object.decode('ascii', 'ignore') print(string_object)