help with list - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: help with list (/thread-16473.html) |
help with list - lateublegende - Mar-01-2019 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. RE: help with list - snippsat - Mar-01-2019 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' RE: help with list - lateublegende - Mar-01-2019 thank for the help, is very well explained. |