Search code examples
pythondomminidom

Extending Python Minidom


There's a way to extends minidom?

I've tried this test with ZipFile and it works:

Having this code in file testzip.py:

import zipfile

class zip( zipfile.ZipFile ):
   def test( self ):
      print( 'test' )

this example code works fine:

import sys
import testzip

zip = testzip.zip( sys.argv[1], 'r' )
zip.test()

I have tried in many ways to do the same with minidom, but without results.

Basically, I would like a class having minidom methods and user-defined methods:

import myminidom

doc = myminidom.parseString( txt )
doc.getElementsByTagName("meta")
doc.customMethod1( customArg1 )

There's a way to obtains this, or is it impossible? I've tried with class myminidom( minidom ) and I understand it's not possible because I can't extends an object, i've tried with class myminidom( minidom.parseStr ), but i got a TypeError: function() argument 1 must be code, not str...


Solution

  • minidom is not a class. its a module, you cannot inheret modules. You can make a proxy if you really want to

    see: How to proxy all methods from a Python module to another?