Get comparison result as an object model

Get comparison result as an object model in Python

GroupDocs.Comparison for Python via .NET allows you to obtain the result document object model after comparing files.

To get the result document object, follow these steps:

  1. Instantiate the Comparer object. Provide the source document path or stream.\
  2. Call the add() method and provide the target document path or stream.\
  3. Call the compare() method and assign its return value to a Document object.

With the Document object, you can access the file name, detected changes, stream, and other information. The object model is fully compatible with Aspose libraries, so you can also use it for advanced processing.

Example: Obtain the result document object and get changes

import groupdocs.comparison as gc

source_path = "source.docx"
target_path = "target.docx"
result_path = "result.docx"

# Initialize comparer with the source document
with gc.Comparer(source_path) as comparer:
    # Add target document
    comparer.add(target_path)

    # Perform comparison and get the result Document object
    result_document = comparer.compare(result_path)

    # Iterate through detected changes
    for change in result_document.changes:
        print("\033[92mSource text:\033[0m", change.source_text)  # green
        print("\033[94mTarget text:\033[0m", change.target_text, "\n")  # blue

The result will list source and target text segments for each detected change.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.