Mar-01-2019, 02:14 PM
(This post was last modified: Mar-01-2019, 02:16 PM by lateublegende.)
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.
help with list
|
Mar-01-2019, 02:14 PM
(This post was last modified: Mar-01-2019, 02:16 PM by lateublegende.)
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.
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'
Mar-01-2019, 05:08 PM
thank for the help, is very well explained.
|
|