Hi,
I noticed that in the documentation, the comment object should have multiples attributes, including id, date, text, etc.
|
Adding a Comment |
|
---------------- |
|
|
|
A simple example is adding a comment to a paragraph:: |
|
|
|
>>> from docx import Document |
|
>>> document = Document() |
|
>>> paragraph = document.add_paragraph("Hello, world!") |
|
|
|
>>> comment = document.add_comment( |
|
... runs=paragraph.runs, |
|
... text="I have this to say about that" |
|
... author="Steve Canny", |
|
... initials="SC", |
|
... ) |
|
>>> comment |
|
<docx.comments.Comment object at 0x02468ACE> |
|
>>> comment.id |
|
0 |
|
>>> comment.author |
|
'Steve Canny' |
|
>>> comment.initials |
|
'SC' |
|
>>> comment.date |
|
datetime.datetime(2025, 6, 11, 20, 42, 30, 0, tzinfo=datetime.timezone.utc) |
|
>>> comment.text |
|
'I have this to say about that' |
On my laptop, I ran the following:
>>> from docx import Document
>>> document = Document()
>>> p = document.add_paragraph("Hello, world!")
>>> comment = document.add_comment(runs = p.runs, text="I have this to say about that", author="Steve Canny", initials="SC",)
>>> comment
<docx.comments.Comment object at 0x10b503230>
>>> comment.id
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Comment' object has no attribute 'id'
>>> comment.author
'Steve Canny'
>>> comment.initials
'SC'
>>> comment.text
'I have this to say about that'
>>> comment.timestamp
datetime.datetime(2026, 5, 5, 12, 5, 44, tzinfo=datetime.timezone.utc)
>>> document.comments
<docx.comments.Comments object at 0x10b555130>
>>> len(document.comments)
1
>>> c = document.comments.get(0)
>>> c
<docx.comments.Comment object at 0x10b536ed0>
>>> [(o, type(getattr(c, o))) for o in dir(c) if not o.startswith("_")]
[('add_paragraph', <class 'method'>), ('add_table', <class 'method'>), ('author', <class 'str'>), ('comment_id', <class 'int'>), ('initials', <class 'str'>), ('iter_inner_content', <class 'method'>), ('paragraphs', <class 'list'>), ('part', <class 'docx.parts.comments.CommentsPart'>), ('tables', <class 'list'>), ('text', <class 'str'>), ('timestamp', <class 'datetime.datetime'>)]
The available attributes are:
author
comment_id
intitials
paragraphs
part
tables
text
@scanny, would you like a PR to fix the doc?
Hi,
I noticed that in the documentation, the
commentobject should have multiples attributes, includingid,date,text, etc.python-docx/docs/user/comments.rst
Lines 82 to 108 in e454546
On my laptop, I ran the following:
The available attributes are:
authorcomment_idintitialsparagraphsparttablestext@scanny, would you like a PR to fix the doc?