Python misunderstandings about bytes methods on digital conversion, the importance of Json, and pythonjson
This article originated from a mistake and found that you can enter a number in bytes (). The transferred bytes are also of the bytes type, so you are eager to decode the content. the result is null. I thought it was a command that was not skilled. In fact, the logic was wrong.
a1 = bytes('11', encoding='utf-8')print(a1)b1 = a1.decode()print(b1)a2 = bytes(11)print(a2)b2 = a2.decode()print(b2)
Incorrect logic: bytes converts the int type to the byte type, and then converts the byte type back to the int type through decode.
Int can indeed be converted to byte, but it cannot be converted back to int unless you define a function or use some complicated built-in commands.
Http://m.blog.csdn.net/crylearner/article/details/38521685
-----------------------------------------------
The basic tutorial will usually ask you to try to convert int to str, and then str to byte. During decode, it is also very troublesome to convert byte to str and then to int. Although this logic is correct.
It seems that in simple programming, str cannot be bypassed!
References: http://www.cnblogs.com/zanjiahaoge666/p/6402907.html
--------------------------------------------------
Secret Weapon Json
Think of more, in case I want to convert an array to byte, or a dictionary, it will make it more complicated.
In fact, you should not forget a non-complex tool, that is, Json. With Json, You can soar all data conversion and recovery!
Not only array, Dictionary, or even music, but also video file. Json.
Academic or football analysis and exchange: chinamaths (in discussion group)
Don't hesitate to comment or add a like-Yours Bill |
Bill's technical blog |
Football analysis blog |
Full Color data video |
Bill geek log_blog |
Bill football data _ Netease blog |
Football TV _ Youku |
Bill geek log_csdn |
Bill football data _ Sina Blog |
Football TV _ Sohu video |
Bill geek log_51cto |
Bill football data _ Sina Weibo |
Football TV _ Himalayan |
Bill geek log_open source China |
Bill football data _ official URL |
Full Color TV _56 video |
Bill geek log_github |
Bill football data _ toutiao.com |
No.: zucai99 |