There are two types of python3 that represent the sequence of characters: bytes and str. An instance of the former contains the original 8-bit value, and the instance of the latter contains Unicode characters.There are also two types of python2 that
absrtact : When writing Python scripts, if we use Python to process Web page data or work with Chinese characters, this error message often occurs: syntaxerror:non-ascii character ' \ Xe6 ' in file./filename.py of Line 3, but no encoding declared.
Here is my understanding. If there is something wrong with me. Please be sure to tell me. Thank you!
In python, __str _ is generally in this format.
Class:
Def _ STR _ (Self ):
Return "this is in Str"
In fact, __str _ is called by the print
In Python processing Chinese, reading files or messages, if found garbled (string processing, read and write files, print), most people's practice is to call Encode/decode for debugging, and did not explicitly consider why garbled, today we discuss
Solution to unicode problems related to str in Python2.x, python2.xunicode
Processing Chinese in python2.x is a headache. I am going to summarize this article here because I am not doing well in the tests and it will be a bit wrong.
I will also
In this blog, "Python string series," The following is covered:
Python built-in STR objects and operations
Formatting of strings
Unicode strings in Python
Regular expressions in Python
Re module
This article describes
It is a headache to deal with Chinese in python2.x. On the Internet to write this aspect of the article, the test time is not neat, and will be a bit wrong, so here intend to summarize an article.
I will also study in the future, and constantly
ImportSocketImportSysport=51423Host="localhost"Data=b"x"*10485760#在字符串前加 B is the string into the bytes class. sock=Socket.socket (Socket.af_inet,socket. Sock_stream) Sock.connect ((host,port)) Byteswritten=0 whilebyteswrittenlen (data):
Methods of processing str and Unicode in Python2015/03/25 · Basic Knowledge · 3 Reviews · Pythonshare to: Source: liuaiqi627 's BlogIt is a headache to deal with Chinese in python2.x. Write this article on the net, the measurement is not homogeneous,
All strings printed in Python are enclosed in quotation marks. This is because when Python prints the value, it keeps the value in the Python code state, not the state you want the user to see, and if you use the print statement, the result is
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.