range property

Node.range property

Returns a Range object that represents the portion of a document that is contained in this node.

Examples

Shows how to delete all the nodes from a range.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

# Add text to the first section in the document, and then add another section.
builder.write("Section 1. ")
builder.insert_break(aw.BreakType.SECTION_BREAK_CONTINUOUS)
builder.write("Section 2.")

self.assertEqual("Section 1. \fSection 2.", doc.get_text().strip())

# Remove the first section entirely by removing all the nodes
# within its range, including the section itself.
doc.sections[0].range.delete()

self.assertEqual(1, doc.sections.count)
self.assertEqual("Section 2.", doc.get_text().strip())

See Also