bytes:
Is a collection of bytes define the type of a bunch of bytes, character string type in python are bytes beginning at b
bytes action:
The computer can store binary, our characters, pictures, videos, music and want to save to your hard drive, it must be the right way and then encoded into binary deposit
For text, we can gbk coding, it can also be utf-8, ASCII encoding.
For images, it must be encoded as a PNG, JPEG and other formats
For music to be encoded into MP3, WAV, etc.
Can save to your hard drive after the python, the string must be encoded into bytes: Remarks. Nor encoded string and then saved the file when I learned of the operation before it, ha, that's the default python help you done this thing, in the default encoding file storage python3 is utf-8.
Files in binary mode:
f = Open ( File = "encode_test" , the MODE = "wb" ) # wb open files in binary mode
Open the file in binary mode there
wb Create a binary
rb binary read
Additional binary ab
Character encoding conversion
Definition: transcoding refers to encoding transformed into another code, such as utf-8 to gbk.
Why do I need transcoding it?
Because different operating system code, utf-8 can not look directly at the win, because the windows are encoded by GBK, it was turned into gbk. If you turn the normal display with the GBK character on Linux \ Mac, you have to turn into utf-8 encoding.
encode decode
Remarks:
In py3, the memory of the string is encoded in unicode, unicode One of the features is now
All languages have coded mapping relationship. So your utf-8 file format on windows PC to see if it can not, you can put the first decoded into utf-8 unicode, gbk re-encode the unicode into it.
Note, whether in Windows or Mac or Linux, you pycharm IDE can support a variety of file encoding, so even utf-8 files, you can also display properly in the windows pycharm
Shallow copy