For a detailed introduction to Isalpha

Source: Internet
Author: User
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?

Related Article

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.