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
  Find strings by index from a list of indexes in a different Pandas dataframe column Calab 3 1,671 Aug-26-2024, 04:52 PM
Last Post: Calab
  [solved] list of list with one or more empty one paul18fr 5 4,665 Oct-04-2023, 09:08 AM
Last Post: jeffreyteague
Sad ValueError: could not convert string to float badju 0 5,454 Jul-01-2021, 12:13 AM
Last Post: badju
  Join each list elements with string in other DF handy88 0 1,991 Feb-09-2021, 07:00 PM
Last Post: handy88
  Convert Strings to Floats samalombo 2 3,377 Jun-08-2020, 10:45 AM
Last Post: hussainmujtaba
  Indirectlty convert string to float in JSON file WBPYTHON 6 8,262 May-06-2020, 12:09 PM
Last Post: WBPYTHON
  ValueError: could not convert string to float RahulSingh 3 5,436 Apr-09-2020, 02:59 PM
Last Post: dinesh
  Convert dataframe string column to numeric in Python darpInd 1 2,968 Mar-14-2020, 10:07 AM
Last Post: ndc85430
  How to use list of symbols for sympy calculation in python? tanmaybhise 1 3,711 Mar-01-2020, 10:36 PM
Last Post: Gribouillis
  ValueError: could not convert string to float: '4 AVENUE' Kudzo 4 7,515 Jan-26-2020, 10:47 PM
Last Post: Kudzo

Forum Jump:

User Panel Messages

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