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

Created on 22 Mar 2017  路  2Comments  路  Source: python-openxml/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

Most helpful comment

As a matter of fact, docx.Document(...) is actually a method, which returns an object of the docx.document.Document class.
You hve been trying to treat this (docx.Document()) method as a class.

Hence, you shall use both the following imports, in order to get the visibility of the contents of docx.document.Document class:

from docx import Document
from docx.document import Document

I've commented over this closed issue, to highlight that perhaps they should have named this method by following the naming convention.
Say something like docx.create_document(...) -> docx.document.Document.

All 2 comments

This question would be better posted on StackOverflow. This issues list is for suspected bugs and feature requests.

As a matter of fact, docx.Document(...) is actually a method, which returns an object of the docx.document.Document class.
You hve been trying to treat this (docx.Document()) method as a class.

Hence, you shall use both the following imports, in order to get the visibility of the contents of docx.document.Document class:

from docx import Document
from docx.document import Document

I've commented over this closed issue, to highlight that perhaps they should have named this method by following the naming convention.
Say something like docx.create_document(...) -> docx.document.Document.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

norecces picture norecces  路  7Comments

JiyhonLiu picture JiyhonLiu  路  3Comments

bendaojiu picture bendaojiu  路  5Comments

avvRobertoAlma picture avvRobertoAlma  路  7Comments

Tores76 picture Tores76  路  6Comments