Python Forum
convert a list of string+bytes into a list of strings (python 3)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert a list of string+bytes into a list of strings (python 3)
#5
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 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")
Reply


Messages In This Thread
RE: convert a list of string+bytes into a list of strings (python 3) - by markfilan - Mar-17-2020, 07:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [solved] list of list with one or more empty one paul18fr 5 2,386 Oct-04-2023, 09:08 AM
Last Post: jeffreyteague
Sad ValueError: could not convert string to float badju 0 4,321 Jul-01-2021, 12:13 AM
Last Post: badju
  Join each list elements with string in other DF handy88 0 1,538 Feb-09-2021, 07:00 PM
Last Post: handy88
  Convert Strings to Floats samalombo 2 2,547 Jun-08-2020, 10:45 AM
Last Post: hussainmujtaba
  Indirectlty convert string to float in JSON file WBPYTHON 6 5,939 May-06-2020, 12:09 PM
Last Post: WBPYTHON
  ValueError: could not convert string to float RahulSingh 3 4,187 Apr-09-2020, 02:59 PM
Last Post: dinesh
  Convert dataframe string column to numeric in Python darpInd 1 2,297 Mar-14-2020, 10:07 AM
Last Post: ndc85430
  How to use list of symbols for sympy calculation in python? tanmaybhise 1 2,795 Mar-01-2020, 10:36 PM
Last Post: Gribouillis
  ValueError: could not convert string to float: '4 AVENUE' Kudzo 4 5,928 Jan-26-2020, 10:47 PM
Last Post: Kudzo
  TypeError: expected string or bytes-like object twinpiques 1 25,741 May-06-2019, 08:29 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020