Today when I write a search component, I want to select the fields to search based on whether the search is all letters. So there is the following code: if Q.isalpha (): query = Query.filter (User.username.ilike (like_str)) Else:query = Query.filter ( User.realname.ilike (LIKE_STR)) but found that even Chinese in it was judged to be isalpha true. The test finds that the method Isalpha in Str is unreliable in judging Unicode. In Flask, the parameter decoding is UTF-8 by default. So the function needs to be re-encoded using encode (' Utf-8 ') isal
1. Isalpha in Python 2.7 does not support Unicode
Summary: Today when I write a search component, I want to select the fields to search based on whether the search is all letters. So there is the following code: if Q.isalpha (): query = Query.filter (User.username.ilike (like_str)) Else:query = Query.filter ( User.realname.ilike (LIKE_STR))
2. Method for checking whether a string is composed of letters in Python: String.isalpha ()
Summary: The python String.isalpha () method Python string Isalpha () method checks whether a string consists of only alphabetic characters.
3. Python Learning Basics of string processing understanding
Summary: Python string processing string input: My_string = raw_input ("Please input a word:") string Judgment: (1) The judgment is not a pure letter my_string.isalpha () string search matches: (1) Rere Regular Expression Instance one: ^[\w_]*$ first \w means matching any word character that includes an underscore, equivalent to ' [a-za-z0-9_] '. And then followed a _. Look at the * Number: match the preceding sub-expression
4. Use of the Isalpha () method for handling strings in Python
Introduction: This article mainly introduces the use of the Isalpha () method of processing strings in Python, which is the basic knowledge of Python's introductory learning, and the need for a friend to refer to the following
"Related question and answer recommendation":
Python-Why is the Unicode Chinese string, call Isalpha () or isalnum () returned True?