GetAttr (), SetAttr (), delattr (), hasattr ()

Source: Internet
Author: User

getattr function syntax format: GetAttr (object, name[, default) parameter is an object, object property value, object property does not exist the corresponding default value name must be a string. If name is the property of an object, the value of that name is returned. For example, GetAttr (x, ' Foobar ') is equivalent to X.foobar. If name does not exist, and there is a default argument, default is returned; otherwise the attributeerror is thrown.

setattr function syntax format: SetAttr (object, name, value) GetAttr () the opposite operation. Parameters are an object, a string, and any value. Name can be a property that exists for an object, or you can add a new property name to an object. This function assigns a value to the Name property, as long as the object is allowed. For example, SetAttr (x, ' Foobar ', 123) is equivalent to X.foobar = 123.

The hasattr function syntax format: The Hasattr (object, name) argument is an objects and a string, respectively. Returns TRUE if name is the property of the object, otherwise false. (implemented by calling GetAttr (object, name) to see if it throws an exception).

delattr function syntax format: The Delattr (object, name) argument is an object and a string this function and SetAttr () about name must be an object's property. This function deletes the Name property as long as the object allows it. For example, delattr (x, ' Foobar ') is equivalent to Del X.foobar.

Reference Document: Http://python.usyiyi.cn/translate/python_278/library/functions.html

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.