Home/ Reference/ Pitfalls

len(doc.Pages) may not work

Use doc.Pages.Count instead of len(doc.Pages).

Symptom

len(doc.Pages) may not work

Notes

Use doc.Pages.Count instead of len(doc.Pages).

Python example (runnable)

Requires pywin32. The example assumes app / doc / page / layer are already connected. See Connection & Init
Python
# never write len(doc.Pages); COM collections may not support it
n = doc.Pages.Count                  # correct
print("Pages: ", n)

for i in range(1, n + 1):
    print(i, doc.Pages.Item(i).SizeWidth)

About this section: Pitfalls

Pitfalls — errors that fail without raising.

Other entries in this section