Experimented with unicode, decode and encode

I'll always forget it, so make a note of it str: unicode = "A": "U + 3042" Encode unicode to str decoding str makes unicode When operating a combination of two character strings, it is necessary to align them to either one. There are different types of unicode such as shift_jis and utf-8, so you need to specify them. u "Japanese" becomes unicode (It was written that it was clearly stated that it was utf-8, but I don't understand the meaning. It's unicode) I'm not sure who "\ #!--coding: utf-8--" is (this also declares that the source is written in utf-8, but it's easy. I feel like it's a lie. What if I save it in sjis and declare it?)

unicode_encode_decode


#!-*- coding: utf-8 -*-
import re
course_key = "test:April 05, 2012:00:00〜00:00"
print type(course_key)
#<type 'str'>
u_course_key = u"test:April 05, 2012:00:00〜00:00"
print type(u_course_key)
#<type 'unicode'>
unicode_key = course_key.decode("utf-8")
print type(unicode_key)
#<type 'unicode'>
encode_key = unicode_key.encode("utf-8")
print type(encode_key)
#<type 'str'>
time_zone =  re.sub(r'.*(\d{2}Month\d{2}Day:\d{2}:\d{2}〜\d{2}:\d{2}).*',r'\1',course_key)
print type(time_zone)
#<type 'str'>
print time_zone
#April 05:00:00〜00:00

Recommended Posts

Experimented with unicode, decode and encode
Python2 str / unicode and encode / decode
Base64 decode / encode
str and unicode
str and unicode
Python2 str / unicode and encode / decode
About _ and __
Decode ShiftJIS to Unicode
With and without WSGI
Manually fix pip install not possible with Unicode Decode Eroor
With me, cp, and Subprocess
Programming with Python and Tkinter
Encryption and decryption with Python
Python and hardware-Using RS232C with Python-
Super-resolution with SRGAN and ESRGAN
group_by with sqlalchemy and sum
python with pyenv and venv
With me, NER and Flair
Works with Python and R