'Subclassing' a Function in Python?
<p>I'm working with the <code>docx</code> library in Python, and I was hoping to create a subclass <code>NewStyleDoc</code> of the <code>Document</code> class from <code>docx</code>.  I attempted to do this as follows:</p>

<pre><code>from docx import Document
class NewStyleDocument(Document):
    # stuff
</code></pre>

<p>And I received the error:</p>

<pre><code>TypeError: function() argument 1 must be code, not str
</code></pre>

<p>Which means <code>Document</code> is actually a function.  (I verified this with <code>type(Document)</code>)  My question is: can I define a class that inherits all of the properties of <code>Document</code>?  My ultimate goals is simple: I just want to do:</p>

<pre><code>doc = NewStyleDocument()
</code></pre>

<p>and have some custom fonts.  (Usually you have to modify styles each time you create a new document.)  Maybe there is an easier way?</p>

<p>This is from the documentation.  Your issue seems to be you are using a constructor built into the module, not into the object.</p>

<pre><code>Document objectsÂ¶
   class docx.document.Document[source]

   WordprocessingML (WML) document. Not intended to be constructed directly. Use docx.Document() to open or create a document.
</code></pre>

<p>So you need to add another layer in there (Docx.document.Document)</p>

python inheritance docx