473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Strange xml.parsers.xml import problem

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
2 3716
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Will Stuyvesant | last post by:
There seems to be no XML parser that can do validation in the Python Standard Libraries. And I am stuck with Python 2.1.1. until my web master upgrades (I use Python for CGI). I know pyXML has...
0
by: dagurp | last post by:
I have this code: import xml.parsers.expat parser = xml.parsers.expat.ParserCreate(encoding="UTF-8") text = unicode("<div>þórður</div>",'UTF-8') print parser.Parse(text,1) And this is what I...
3
by: Christoph Zwerschke | last post by:
Just hitting a strange problem with Python import behavior. It is the same on all Python 2.x versions and it is probably correct, but I currently don't understand why this happens. I have...
2
by: Nainesh Jhaveri | last post by:
I have a ton of Business logic writter in Java, which I am trying to expose to .NET platform using Visual J#. NET. The java code is making extensive use of java.rmi.* package. but, the latest...
6
by: robert | last post by:
I get python crashes and (in better cases) strange Python exceptions when (in most cases) importing and using cookielib lazy on demand in a thread. It is mainly with cookielib, but remember the...
5
by: IloChab | last post by:
Sorry I wasn't able to be more specific on my topic but I really do not know how to classify my problem, I mean that I can't understand if it's a python or a twisted or a Qt4 problem I'm...
0
by: JosAH | last post by:
Greetings, welcome back at the sequel of the parsers article chapter. This part is dedicated to the ExpressionParser, the largest parser class for our little language. This class parses a...
0
by: JosAH | last post by:
Greetings, this week's article part discusses the parsers used for our little language. We will implement the parsers according to the grammar rules we defined in the second part of this...
2
by: Spes | last post by:
Hi, I have this simple code: | #!/usr/bin/python | import codecs | import re | from copy import deepcopy | | class MyClass(object): | def __del__(self):
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.