Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with list
#1
when I print the value of my list, he print b'value' and I don't know why the program does that. I think is binairy, but I need the value only.
Reply
#2
It's not binary,but bytes.
Where dos data in you list come from?
All data that come into Python 3 most have encoding,if not it will be bytes.
This is because of Unicode,which was one biggest changes moving to Python 3.

Can convert with decode() encode().
>>> lst = [b'value', b'hello', b'9999']
>>> lst[0]
b'value'
>>> type(lst[0])
<class 'bytes'>

>>> # To str also default Unicode text Python 3
>>> lst[0].decode() # Same as .decode('utf-8')
'value'
>>> [i.decode() for i in lst]
['value', 'hello', '9999']
Can also work with bytes,eg string method works.
>>> lst[0].upper()
b'VALUE'
Reply
#3
thank for the help, is very well explained.
Reply


Forum Jump:

User Panel Messages

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