Created
October 5, 2015 14:34
-
-
Save walkerdb/6a6f732bdbc7030cf42a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # accessing attribute values: | |
| >>> container.attrib.get("type", "") | |
| "box" | |
| >>> container.attrib.get("location", "") | |
| "" # since the "location" attribute does not exist, the .get() function returns an empty string | |
| # changing a current value or creating a new attribute | |
| >>> container.attrib["type"] = "folder" | |
| # creating a new attribute only if the attribute does not already exist: | |
| >>> container.attrib["label"] = container.attrib.get("label", "Folder") | |
| # deleting an attribute | |
| >>> del container.attrib["label"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment