python-docx - deleting first paragraph
<p>When I create a new document with python-docx and add paragraphs, it starts at the very first line. But if I use an empty document (I need it because of the user defined styles) and add paragraphes the document would always start with an empty line. Is there any workaround?</p>

<p>You can call <code>document._body.clear_content()</code> before adding the first paragraph.</p>

<pre><code>document = Document('my-document.docx')
document._body.clear_content()
# start adding new paragraphs and whatever ...
</code></pre>

<p>That will leave the document with no paragraphs, so when you add new ones they start at the beginning.</p>

<p>It does, however, leave the document in a technically invalid state. So if you didn't add any new paragraphs and then tried to open it with Word, you might get a repair error on loading.</p>

<p>But if the next thing you're doing is adding paragraphs of your own, this should work just fine.</p>

<p>Also, note that this is technically an "internal" method and is not part of the documented API. So there's no guarantee this method's name won't change in a future release. But frankly I can't see any reason to change or remove it, so I expect it's safe enough :)</p>

python python-docx