Search code examples
pythonpython-docx

why my IDE can't Auto-Complete for python-docx?


when i use python-docx , my IDE ,like pycharm wing , can't Auto-Complete it. this code

from docx import Document

asd = Document()
asd.add_heading("test")
asd.save("cao.docx")

when i typing asd. add_heading can't Auto-Complete.

from docx.document import Document  

asd = Document()
asd.save()
this code can Auto-Complete
but atention

TypeError: init() missing 2 required positional arguments: 'element' and 'part'

I am sorry for my poor english


Solution

  • In the latter case, you are mistakenly importing docx.document.Document rather than docx.Document. The Document class in docx.document has a different call signature and in any case isn't the one you want :)