Python misunderstandings about bytes methods on digital conversion, the importance of Json, and pythonjson

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.