Strange xml.parsers.xml import problem

dwelch91 at gmail.com dwelch91 at gmail.com
Fri Sep 15 20:49:14 CEST 2006


Hi, c.l.p.'ers-

I am having a problem with the import of xml.parsers.expat that has
gotten me completely stumped. I have two programs, one a PyQt program
and one a command line (text) program that both eventually call the
same code that imports xml.parsers.expat. Both give me different
results...

The code that gets called is (print statements have been added for
debugging):

    # this is status.py
    import xml.parsers.expat
    print xml
    print xml.parsers
    print dir(xml.parsers)
    print repr(xml.parsers.expat.ExpatError)
    print xml.parsers.expat

    if info_device_status:
        try:
            device_status =
utils.XMLToDictParser().parseXML(info_device_status)
            log.debug_block("info_device_status", info_device_status)
            log.debug(device_status)
        except xml.parsers.expat.ExpatError:
            log.error("Device Status XML parse error")
            device_status = {}

    if info_ssp:
        try:
            ssp = utils.XMLToDictParser().parseXML(info_ssp)
            log.debug_block("info_spp", info_ssp)
            log.debug(ssp)
        except xml.parsers.expat.ExpatError:
            log.error("SSP XML parse error")
            ssp = {}

When I run this code from my console program, it prints out:

<module '_xmlplus' from
'/usr/lib/python2.4/site-packages/_xmlplus/__init__.pyc'>
<module 'xml.parsers' from
'/usr/lib/python2.4/site-packages/_xmlplus/parsers/__init__.pyc'>
['__all__', '__builtins__', '__doc__', '__file__', '__name__',
'__path__', 'expat', 'pyexpat']
<class xml.parsers.expat.ExpatError at 0x2aaaac6c6950>
<module 'xml.parsers.expat' from
'/usr/lib/python2.4/site-packages/_xmlplus/parsers/expat.pyc'>

and all is well...

However, from the PyQt program I get:

<module '_xmlplus' from
'/usr/lib/python2.4/site-packages/_xmlplus/__init__.pyc'>
<module '_xmlplus.parsers' from
'/usr/lib/python2.4/site-packages/_xmlplus/parsers/__init__.pyc'>
['__all__', '__builtins__', '__doc__', '__file__', '__name__',
'__path__', 'sgmlop']
Traceback (most recent call last):

[...snip...]

  File
"/home/dwelch/tip/linux-imaging-and-printing/src/base/status.py", line
980, in StatusType6
    print repr(xml.parsers.expat.ExpatError)
AttributeError: 'module' object has no attribute 'expat'

Somehow, the import has brought in "_xmlplus" rather than "xml", and
"expat" is no longer in the xml.parsers module. This is on the same
machine with the same user account, running each program "back to
back". Running each program as a different user made no difference.

Everything is also OK if I manually enter the import and print commands
into a Python >>> prompt.

Any help much appreciated!

-Don




More information about the Python-list mailing list