Python encounters (later to classify)

Source: Internet
Author: User

1.rsplit ():P Ython string application function

1 def Load_class (s): 2     Path, Klass = S.rsplit ('. ', 1)3     __import__(path)4     mod =  Sys.modules[path]5     return getattr (mod, Klass)

2.__import__ () Python built-in function that can be imported directly into the module

3.getattr:python built-in function: Used to return an object's properties or methods

1 assert Issubclass (Self.database_class, PeeWee. Database)

1.issubclass: Built-in function Issubclass (class, ClassInfo) to determine if class is ClassInfo subclass

2.assert:python's assert is used to check a condition, and if it is true, it does nothing. If it is false, it throws a Asserterror and contains an error message

1.encode: In encoding conversion, it is usually necessary to use Unicode as the intermediate encoding, that is, the other encoded strings are decoded (decode) into Unicode, and then from Unicode encoding (encode) to another encoding.

2.xrange: Similar to Range: But unlike range, which produces a list, xrange produces a generator.

So xrange do loop performance better than range, especially when returning very large, try to use Xrange bar, unless you are going to return a list

Http://ciniao.me/article.php?id=17

3.enumerate: A sequence can be generated

Python encounters (later to classify)

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.