Skip to content

Instantly share code, notes, and snippets.

@walkerdb
Created October 5, 2015 14:34
Show Gist options
  • Select an option

  • Save walkerdb/6a6f732bdbc7030cf42a to your computer and use it in GitHub Desktop.

Select an option

Save walkerdb/6a6f732bdbc7030cf42a to your computer and use it in GitHub Desktop.
# 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