where is the word/_rels/document.xml.rels in python docx object? -


i need content of word/_rels/document.xml.rels image infomation. python-docx store it?

i use this:

>>> docx import document d >>> x=d('a.docx') 

there seems no way in x object.

python-docx , python-pptx share common opc subpackage; docx.opc subpackage.

this layer abstracts details of .rels files, among other things.

you can using:

>>> document = document() >>> document_part = document.part >>> rels = document_part.rels >>> r in rels: ...   print r.rid 'rid2' 'rid1' 'rid3' 

how use depends on you're trying at. 1 wants related part , doesn't care navigating details of packaging. there these higher level methods:

  • docx.opc.part.part.part_related_by()
  • docx.opc.part.part.related_parts[rid]

in general route object @ hand is:

  1. to part it's contained in (often available on obj.part)
  2. to related part use of .part_related_by() (using relationship type) or .related_parts[rid] (it's dict).
  3. back down the api object via x_part.main_obj e.g. documentpart.document

the areas in code might interested in looking closer @ are:

  • docx/parts/
  • docx/opc/part.py

Comments