MCPcopy Index your code
hub / github.com/python-openxml/python-docx / next_partname

Method next_partname

src/docx/opc/package.py:109–121  ·  view source on GitHub ↗

Return a |PackURI| instance representing partname matching `template`. The returned part-name has the next available numeric suffix to distinguish it from other parts of its type. `template` is a printf (%)-style template string containing a single replacement item, a '%d' t

(self, template: str)

Source from the content-addressed store, hash-verified

107 return self.part_related_by(RT.OFFICE_DOCUMENT)
108
109 def next_partname(self, template: str) -> PackURI:
110 """Return a |PackURI| instance representing partname matching `template`.
111
112 The returned part-name has the next available numeric suffix to distinguish it
113 from other parts of its type. `template` is a printf (%)-style template string
114 containing a single replacement item, a '%d' to be used to insert the integer
115 portion of the partname. Example: "/word/header%d.xml"
116 """
117 partnames = {part.partname for part in self.iter_parts()}
118 for n in range(1, len(partnames) + 2):
119 candidate_partname = template % n
120 if candidate_partname not in partnames:
121 return PackURI(candidate_partname)
122
123 @classmethod
124 def open(cls, pkg_file: str | IO[bytes]) -> Self:

Callers 3

newMethod · 0.80
newMethod · 0.80

Calls 2

iter_partsMethod · 0.95
PackURIClass · 0.90