By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,939 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,939 IT Pros & Developers. It's quick & easy.

Strange xml.parsers.xml import problem

P: n/a
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_statu s)
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

Sep 15 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Sorry, that should have been "xml.parsers.expat"

dw******@gmail.com wrote:
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_statu s)
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
Sep 15 '06 #2

P: n/a
I was able to fix (i.e., work around) this issue by using the import:

import xml.parsers.expat as expat

and then referring to:

expat.ExpatError

I have no idea why this makes it work, seems like a bug in Python to
me.

-Don
dw******@gmail.com wrote:
Sorry, that should have been "xml.parsers.expat"

dw******@gmail.com wrote:
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_statu s)
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
Oct 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.