我需要了解docx的核心属性,包括作者,语言,创建的(日期),标识符,last_printed,修改的(日期),版本,标题,主题。我写了这段代码:
import docx
import os
os.chdir('C:\\abc\\Documents')
doc = docx.Document('ATD.docx')
docx.opc.coreprops.CoreProperties.author(doc)
我收到此错误:
TypeError:“属性”对象不可调用
如何从python代码中获取所需的信息?
我正在使用python-docx 0.8.10
,不确定当时是否支持core properties,但现在事情应该很简单:
print(doc.core_properties.author)
>> 'name of the author'
为了列出所有可用的属性,请执行以下操作:
print(doc.core_properties.__dir__())
请注意,您还可以为identifier
,author
等属性设置新值。>
doc.core_properties.author = '#stayathome!' # aren't we all enjoying covid-19 print(doc.core_properties.author) >> '#stayathome!'
希望这会有所帮助,
最佳