Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help :)
#11
(Oct-09-2017, 08:59 AM)buran Wrote: b designates it as binary string.
Just to correct that a little,it's bytes string.
You show the correct way with txt.decode('utf-8')

Everything that it's not decoded into Python 3 will be bytes.
He could have decoded earlier:
mydata = pd.read_sas('C:\\Users\\00124118\\Desktop\\call_center_data.sas7bdat', encoding='utf-8')
  
Just to show a binary string:
>>> bin_string = bin(22)
>>> bin_string
'0b10110'
>>> int(bin_string, 2)
22
The normal way that most encounter this in Python 3 is bytes.
>>> s = b'hello'
>>> s
b'hello'
>>> type(s)
<class 'bytes'>

>>> # To python 3 string which is Unicode
>>> s = s.decode('utf-8') # or just decode()
>>> s
'hello'
>>> type(s)
<class 'str'>
Reply
#12
(Oct-09-2017, 11:49 AM)snippsat Wrote: Just to correct that a little,it's bytes string.
yes, my mistake. thanks for pointing it out :-)
Reply
#13
okay! thank you all so much. I have so much to learn about Python :)
Reply


Forum Jump:

User Panel Messages

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