473,757 Members | 10,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xml.dom's weirdness?

Lie
Why this generates AttributeError, then not?

Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>import xml
xml.dom
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'dom'
>>xml.dom
<module 'xml.dom' from '/usr/lib/python2.5/xml/dom/__init__.pyc'>
>>>
Jul 26 '08 #1
9 2481
Lie wrote:
Why this generates AttributeError, then not?

Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>>import xml
xml.dom
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'dom'
>>>xml.dom
<module 'xml.dom' from '/usr/lib/python2.5/xml/dom/__init__.pyc'>
this is what I get, on both Windows and Linux:
>>import xml
xml.dom
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'dom'
>>xml.dom
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'dom'

</F>

Jul 26 '08 #2
Lie
On Jul 26, 2:29*pm, Fredrik Lundh <fred...@python ware.comwrote:
Lie wrote:
Why this generates AttributeError, then not?
Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>import xml
xml.dom
Traceback (most recent call last):
* File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'dom'
>>xml.dom
<module 'xml.dom' from '/usr/lib/python2.5/xml/dom/__init__.pyc'>

this is what I get, on both Windows and Linux:

*>>import xml
*>>xml.dom
Traceback (most recent call last):
* *File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'dom'
*>>xml.dom
Traceback (most recent call last):
* *File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'dom'

</F>
That was what I would have expected. The submodules shouldn't get
imported unless explicitly imported with import xml.dom, but what I
see right now in front of me... I wouldn't have believed such thing if
this isn't happening right under my eyes.

Doing several dir(xml) revealed that xml.dom and xml.parsers appeared
only after doing xml.dom and getting AttributeError

After further testing, I found that it also happens with xml.parsers,
but not xml.sax nor xml.etree, odd thing. And I tried PIL modules, the
oddities doesn't happen.

Then I tested the email module, the same thing happened:

Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>import email
dir(email)
['Charset', 'Encoders', 'Errors', 'FeedParser', 'Generator', 'Header',
'Iterators', 'LazyImporter', 'MIMEAudio', 'MIMEBase', 'MIMEImage',
'MIMEMessage', 'MIMEMultipart' , 'MIMENonMultipa rt', 'MIMEText',
'Message', 'Parser', 'Utils', '_LOWERNAMES', '_MIMENAMES', '__all__',
'__builtins__', '__doc__', '__file__', '__name__', '__path__',
'__version__', '_name', 'base64MIME', 'email', 'importer',
'message_from_f ile', 'message_from_s tring', 'mime', 'quopriMIME',
'sys']
>>email.parse r
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'parser'
>>dir(email)
['Charset', 'Encoders', 'Errors', 'FeedParser', 'Generator', 'Header',
'Iterators', 'LazyImporter', 'MIMEAudio', 'MIMEBase', 'MIMEImage',
'MIMEMessage', 'MIMEMultipart' , 'MIMENonMultipa rt', 'MIMEText',
'Message', 'Parser', 'Utils', '_LOWERNAMES', '_MIMENAMES', '__all__',
'__builtins__', '__doc__', '__file__', '__name__', '__path__',
'__version__', '_name', '_parseaddr', 'base64MIME', 'base64mime',
'charset', 'email', 'encoders', 'errors', 'importer', 'iterators',
'message', 'message_from_f ile', 'message_from_s tring', 'mime',
'quopriMIME', 'quoprimime', 'sys', 'utils']
>>>
It seems python (or my version of python, which is the one that
shipped with Ubuntu) mysteriously imported several modules's
submodules in a (seemingly) random, yet consistent manner after an
error occurred (as far as now, it seems ANY error would trigger the
mysterious submodule import).

I got even more head scratching when I see this:

Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>ac
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'ac' is not defined
>>import xml
dir(xml)
['_MINIMUM_XMLPL US_VERSION', '__all__', '__builtins__', '__doc__',
'__file__', '__name__', '__path__', '__version__', 'dom', 'parsers']
>>>
The triggering errors happened BEFORE I imported a module, yet later
module import would also import submodules

If you have any idea what black magic is happening in my computer
right now, I'd appreciate it.
Jul 26 '08 #3
Lie wrote:
If you have any idea what black magic is happening in my computer
right now, I'd appreciate it.
command completion? (no ubuntu within reach right now, so I cannot
check how they've set it up).

try starting python with the "-v" option, so you can see exactly when
the import occurs.

</F>

Jul 26 '08 #4
Lie
On Jul 26, 6:03*pm, Fredrik Lundh <fred...@python ware.comwrote:
Lie wrote:
If you have any idea what black magic is happening in my computer
right now, I'd appreciate it.

command completion? *(no ubuntu within reach right now, so I cannot
check how they've set it up).

try starting python with the "-v" option, so you can see exactly when
the import occurs.

</F>
I run python as:
python -v &pyth.log

As I've predicted, they imported the modules when there is an Error,
any Error, it seems.

I have made a hypothesis that it seems that there is something wrong
with the Error Handler, it seems that Python have leaked the modules
the Error handler used to my session. Although I am unable to access
the modules itself unless I imported those modules by myself, any sub-
modules that is loaded by the Error Handler is already loaded, so in
my session, those modules are merely rebound to a name in my
namespace.

Question: Is there a way to list loaded modules, including those that
aren't in my namespace?

Remarks:
In another, possibly unrelated, possibly related case, every time I
typed: "help(modul es)" (to list all modules installed on the system)
I've got an error, I've previously made a thread about this in c.l.py,
but I don't really mind that much back then since listing installed
modules aren't that important for me (I can lookup standardly
installed modules in the internet and the number of 3rd party modules
installed, I can count with the fingers from a hand). The thread was:
http://groups.google.com/group/comp....1edb45fb3854a/

This is an example of the terminal session
me@my-computer:~$ python -v &pyth.log
be_nice = 100
doerror
xml
import xml
xml.dom
import email
email.mime
exit()

Python doesn't emit the prompts >>because they're redirected to
pyth.log

Here is the SUMMARY of pyth.log (the real one is very long, so I
append it at the end)

* Typed "python -v &pyth.log" to terminal

* Python imports many modules:
zipimport, site, os, errno, posix, posixpath, stat,
UserDict, copy_reg, types, _types, sitecustomize,
apport_python_h ook, warnings, linecache,
encodings (# directory /usr/lib/python2.5/encodings),
encodings (# precompiled from /usr/lib/python2.5/encodings/
__init__.pyc),
codecs, _codecs, encodings.alias es, encodings.utf_8

* Standard Python Heading:
Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.

* I don't know what this is: dlopen("/usr/lib/python2.5/lib-dynload/
readline.so", 2);

* Python imported readline module

* Python prompt: I typed "be_nice = 100", no output

* Python prompt: I typed "doerror" (since doerror is not defined, it
raises NameError, I've tried many other errors, like arithmetic error,
etc and they did similar thing), python response with loading a lot of
modules:

apport (# directory /usr/lib/python2.5/site-packages/apport),
apport (# precompiled from /usr/lib/python2.5/site-packages/apport/
__init__.pyc),
apport.report, subprocess, traceback, gc, time,
select, fcntl, pickle, marshal, struct, _struct,
re, sre_compile, _sre, sre_constants, sre_parse,
binascii, cStringIO, tempfile, random, math, _random,
thread, urllib, string, strop, socket, _socket, _ssl,
urlparse, pwd, grp, fnmatch, glob, atexit, xml, xml.dom,
xml.dom.domreg, xml.dom.minicom pat, xml.dom.minidom ,
xml.dom.xmlbuil der, copy, xml.dom.NodeFil ter,
xml.parsers (# directory /usr/lib/python2.5/xml/parsers),
xml.parsers (# precompiled from /usr/lib/python2.5/xml/parsers/
__init__.pyc),
xml.parsers.exp at, pyexpat, problem_report, zlib,
base64, gzip, email,
email.mime (# directory /usr/lib/python2.5/email/mime),
email.mime (# precompiled from /usr/lib/python2.5/email/mime/
__init__.pyc),
email.encoders, email.quopri, email.mime.mult ipart,
email.mime.base , email.message, uu, email.charset,
email.base64mim e, email.utils, email._parseadd r,
email.quoprimim e, email.errors, email.iterators ,
email.mime.text , email.mime.nonm ultipart,
unittest, apport.fileutil s, apport.packagin g.impl,
apt (# directory /usr/lib/python2.5/site-packages/apt),
apt (# precompiled from /usr/lib/python2.5/site-packages/apt/
__init__.pyc),
apt_pkg, apt.package, gettext, locale, _locale,
operator, apt.cache, apt.progress, apt.cdrom,
apport.packagin g, shutil.

Among these imports, there are lines like these interleaved (generally
right before the import of the modules with the same name):

dlopen("/usr/lib/python2.5/lib-dynload/time.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/select.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/fcntl.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/_struct.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/binascii.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/cStringIO.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/math.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/_random.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/strop.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/_socket.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/_ssl.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/grp.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/pyexpat.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/zlib.so", 2);
dlopen("/usr/lib/python2.5/site-packages/apt_pkg.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/_locale.so", 2);
dlopen("/usr/lib/python2.5/lib-dynload/operator.so", 2);

* After those imports is the standard Python traceback (because of the
doerror we made earlier)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'doerror' is not defined

* The next few lines (edited[1] form the original, for viewing
convenience):
>>xml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'xml' is not defined
>>import xml
xml.dom
<module 'xml.dom' from '/usr/lib/python2.5/xml/dom/__init__.pyc'>
>>import email
email.mime
<module 'email.mime' from '/usr/lib/python2.5/email/mime/
__init__.pyc'>
[1] Since this is a dump from IO redirection, the texts coming from
stdin is absent, I inserted those stdin manually, so it looks more
like terminal transcript, instead of IO redirection.

* Python prompt - I typed "exit()", it displayed messages of it
clearing itself and cleaning up the modules it have loaded
TERMINAL TRANSCRIPT (the one already edited, to get the original,
apply the diff far below):
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/lib/python2.5/site.pyc matches /usr/lib/python2.5/site.py
import site # precompiled from /usr/lib/python2.5/site.pyc
# /usr/lib/python2.5/os.pyc matches /usr/lib/python2.5/os.py
import os # precompiled from /usr/lib/python2.5/os.pyc
import errno # builtin
import posix # builtin
# /usr/lib/python2.5/posixpath.pyc matches /usr/lib/python2.5/
posixpath.py
import posixpath # precompiled from /usr/lib/python2.5/posixpath.pyc
# /usr/lib/python2.5/stat.pyc matches /usr/lib/python2.5/stat.py
import stat # precompiled from /usr/lib/python2.5/stat.pyc
# /usr/lib/python2.5/UserDict.pyc matches /usr/lib/python2.5/
UserDict.py
import UserDict # precompiled from /usr/lib/python2.5/UserDict.pyc
# /usr/lib/python2.5/copy_reg.pyc matches /usr/lib/python2.5/
copy_reg.py
import copy_reg # precompiled from /usr/lib/python2.5/copy_reg.pyc
# /usr/lib/python2.5/types.pyc matches /usr/lib/python2.5/types.py
import types # precompiled from /usr/lib/python2.5/types.pyc
import _types # builtin
# /usr/lib/python2.5/sitecustomize.p yc matches /usr/lib/python2.5/
sitecustomize.p y
import sitecustomize # precompiled from /usr/lib/python2.5/
sitecustomize.p yc
# /usr/lib/python2.5/site-packages/apport_python_h ook.pyc matches /usr/
lib/python2.5/site-packages/apport_python_h ook.py
import apport_python_h ook # precompiled from /usr/lib/python2.5/site-
packages/apport_python_h ook.pyc
# /usr/lib/python2.5/warnings.pyc matches /usr/lib/python2.5/
warnings.py
import warnings # precompiled from /usr/lib/python2.5/warnings.pyc
# /usr/lib/python2.5/linecache.pyc matches /usr/lib/python2.5/
linecache.py
import linecache # precompiled from /usr/lib/python2.5/linecache.pyc
import encodings # directory /usr/lib/python2.5/encodings
# /usr/lib/python2.5/encodings/__init__.pyc matches /usr/lib/python2.5/
encodings/__init__.py
import encodings # precompiled from /usr/lib/python2.5/encodings/
__init__.pyc
# /usr/lib/python2.5/codecs.pyc matches /usr/lib/python2.5/codecs.py
import codecs # precompiled from /usr/lib/python2.5/codecs.pyc
import _codecs # builtin
# /usr/lib/python2.5/encodings/aliases.pyc matches /usr/lib/python2.5/
encodings/aliases.py
import encodings.alias es # precompiled from /usr/lib/python2.5/
encodings/aliases.pyc
# /usr/lib/python2.5/encodings/utf_8.pyc matches /usr/lib/python2.5/
encodings/utf_8.py
import encodings.utf_8 # precompiled from /usr/lib/python2.5/encodings/
utf_8.pyc
Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
dlopen("/usr/lib/python2.5/lib-dynload/readline.so", 2);
import readline # dynamically loaded from /usr/lib/python2.5/lib-
dynload/readline.so
>>be_nice = 100
doerror
import apport # directory /usr/lib/python2.5/site-packages/apport
# /usr/lib/python2.5/site-packages/apport/__init__.pyc matches /usr/
lib/python2.5/site-packages/apport/__init__.py
import apport # precompiled from /usr/lib/python2.5/site-packages/
apport/__init__.pyc
# /usr/lib/python2.5/site-packages/apport/report.pyc matches /usr/lib/
python2.5/site-packages/apport/report.py
import apport.report # precompiled from /usr/lib/python2.5/site-
packages/apport/report.pyc
# /usr/lib/python2.5/subprocess.pyc matches /usr/lib/python2.5/
subprocess.py
import subprocess # precompiled from /usr/lib/python2.5/subprocess.pyc
# /usr/lib/python2.5/traceback.pyc matches /usr/lib/python2.5/
traceback.py
import traceback # precompiled from /usr/lib/python2.5/traceback.pyc
import gc # builtin
dlopen("/usr/lib/python2.5/lib-dynload/time.so", 2);
import time # dynamically loaded from /usr/lib/python2.5/lib-dynload/
time.so
dlopen("/usr/lib/python2.5/lib-dynload/select.so", 2);
import select # dynamically loaded from /usr/lib/python2.5/lib-dynload/
select.so
dlopen("/usr/lib/python2.5/lib-dynload/fcntl.so", 2);
import fcntl # dynamically loaded from /usr/lib/python2.5/lib-dynload/
fcntl.so
# /usr/lib/python2.5/pickle.pyc matches /usr/lib/python2.5/pickle.py
import pickle # precompiled from /usr/lib/python2.5/pickle.pyc
import marshal # builtin
# /usr/lib/python2.5/struct.pyc matches /usr/lib/python2.5/struct.py
import struct # precompiled from /usr/lib/python2.5/struct.pyc
dlopen("/usr/lib/python2.5/lib-dynload/_struct.so", 2);
import _struct # dynamically loaded from /usr/lib/python2.5/lib-
dynload/_struct.so
# /usr/lib/python2.5/re.pyc matches /usr/lib/python2.5/re.py
import re # precompiled from /usr/lib/python2.5/re.pyc
# /usr/lib/python2.5/sre_compile.pyc matches /usr/lib/python2.5/
sre_compile.py
import sre_compile # precompiled from /usr/lib/python2.5/
sre_compile.pyc
import _sre # builtin
# /usr/lib/python2.5/sre_constants.p yc matches /usr/lib/python2.5/
sre_constants.p y
import sre_constants # precompiled from /usr/lib/python2.5/
sre_constants.p yc
# /usr/lib/python2.5/sre_parse.pyc matches /usr/lib/python2.5/
sre_parse.py
import sre_parse # precompiled from /usr/lib/python2.5/sre_parse.pyc
dlopen("/usr/lib/python2.5/lib-dynload/binascii.so", 2);
import binascii # dynamically loaded from /usr/lib/python2.5/lib-
dynload/binascii.so
dlopen("/usr/lib/python2.5/lib-dynload/cStringIO.so", 2);
import cStringIO # dynamically loaded from /usr/lib/python2.5/lib-
dynload/cStringIO.so
# /usr/lib/python2.5/tempfile.pyc matches /usr/lib/python2.5/
tempfile.py
import tempfile # precompiled from /usr/lib/python2.5/tempfile.pyc
# /usr/lib/python2.5/random.pyc matches /usr/lib/python2.5/random.py
import random # precompiled from /usr/lib/python2.5/random.pyc
dlopen("/usr/lib/python2.5/lib-dynload/math.so", 2);
import math # dynamically loaded from /usr/lib/python2.5/lib-dynload/
math.so
dlopen("/usr/lib/python2.5/lib-dynload/_random.so", 2);
import _random # dynamically loaded from /usr/lib/python2.5/lib-
dynload/_random.so
import thread # builtin
# /usr/lib/python2.5/urllib.pyc matches /usr/lib/python2.5/urllib.py
import urllib # precompiled from /usr/lib/python2.5/urllib.pyc
# /usr/lib/python2.5/string.pyc matches /usr/lib/python2.5/string.py
import string # precompiled from /usr/lib/python2.5/string.pyc
dlopen("/usr/lib/python2.5/lib-dynload/strop.so", 2);
import strop # dynamically loaded from /usr/lib/python2.5/lib-dynload/
strop.so
# /usr/lib/python2.5/socket.pyc matches /usr/lib/python2.5/socket.py
import socket # precompiled from /usr/lib/python2.5/socket.pyc
dlopen("/usr/lib/python2.5/lib-dynload/_socket.so", 2);
import _socket # dynamically loaded from /usr/lib/python2.5/lib-
dynload/_socket.so
dlopen("/usr/lib/python2.5/lib-dynload/_ssl.so", 2);
import _ssl # dynamically loaded from /usr/lib/python2.5/lib-dynload/
_ssl.so
# /usr/lib/python2.5/urlparse.pyc matches /usr/lib/python2.5/
urlparse.py
import urlparse # precompiled from /usr/lib/python2.5/urlparse.pyc
import pwd # builtin
dlopen("/usr/lib/python2.5/lib-dynload/grp.so", 2);
import grp # dynamically loaded from /usr/lib/python2.5/lib-dynload/
grp.so
# /usr/lib/python2.5/fnmatch.pyc matches /usr/lib/python2.5/fnmatch.py
import fnmatch # precompiled from /usr/lib/python2.5/fnmatch.pyc
# /usr/lib/python2.5/glob.pyc matches /usr/lib/python2.5/glob.py
import glob # precompiled from /usr/lib/python2.5/glob.pyc
# /usr/lib/python2.5/atexit.pyc matches /usr/lib/python2.5/atexit.py
import atexit # precompiled from /usr/lib/python2.5/atexit.pyc
import xml # directory /usr/lib/python2.5/xml
# /usr/lib/python2.5/xml/__init__.pyc matches /usr/lib/python2.5/xml/
__init__.py
import xml # precompiled from /usr/lib/python2.5/xml/__init__.pyc
import xml.dom # directory /usr/lib/python2.5/xml/dom
# /usr/lib/python2.5/xml/dom/__init__.pyc matches /usr/lib/python2.5/
xml/dom/__init__.py
import xml.dom # precompiled from /usr/lib/python2.5/xml/dom/
__init__.pyc
# /usr/lib/python2.5/xml/dom/domreg.pyc matches /usr/lib/python2.5/xml/
dom/domreg.py
import xml.dom.domreg # precompiled from /usr/lib/python2.5/xml/dom/
domreg.pyc
# /usr/lib/python2.5/xml/dom/minicompat.pyc matches /usr/lib/python2.5/
xml/dom/minicompat.py
import xml.dom.minicom pat # precompiled from /usr/lib/python2.5/xml/
dom/minicompat.pyc
# /usr/lib/python2.5/xml/dom/minidom.pyc matches /usr/lib/python2.5/
xml/dom/minidom.py
import xml.dom.minidom # precompiled from /usr/lib/python2.5/xml/dom/
minidom.pyc
# /usr/lib/python2.5/xml/dom/xmlbuilder.pyc matches /usr/lib/python2.5/
xml/dom/xmlbuilder.py
import xml.dom.xmlbuil der # precompiled from /usr/lib/python2.5/xml/
dom/xmlbuilder.pyc
# /usr/lib/python2.5/copy.pyc matches /usr/lib/python2.5/copy.py
import copy # precompiled from /usr/lib/python2.5/copy.pyc
# /usr/lib/python2.5/xml/dom/NodeFilter.pyc matches /usr/lib/python2.5/
xml/dom/NodeFilter.py
import xml.dom.NodeFil ter # precompiled from /usr/lib/python2.5/xml/
dom/NodeFilter.pyc
import xml.parsers # directory /usr/lib/python2.5/xml/parsers
# /usr/lib/python2.5/xml/parsers/__init__.pyc matches /usr/lib/
python2.5/xml/parsers/__init__.py
import xml.parsers # precompiled from /usr/lib/python2.5/xml/parsers/
__init__.pyc
# /usr/lib/python2.5/xml/parsers/expat.pyc matches /usr/lib/python2.5/
xml/parsers/expat.py
import xml.parsers.exp at # precompiled from /usr/lib/python2.5/xml/
parsers/expat.pyc
dlopen("/usr/lib/python2.5/lib-dynload/pyexpat.so", 2);
import pyexpat # dynamically loaded from /usr/lib/python2.5/lib-
dynload/pyexpat.so
# /usr/lib/python2.5/site-packages/problem_report. pyc matches /usr/lib/
python2.5/site-packages/problem_report. py
import problem_report # precompiled from /usr/lib/python2.5/site-
packages/problem_report. pyc
dlopen("/usr/lib/python2.5/lib-dynload/zlib.so", 2);
import zlib # dynamically loaded from /usr/lib/python2.5/lib-dynload/
zlib.so
# /usr/lib/python2.5/base64.pyc matches /usr/lib/python2.5/base64.py
import base64 # precompiled from /usr/lib/python2.5/base64.pyc
# /usr/lib/python2.5/gzip.pyc matches /usr/lib/python2.5/gzip.py
import gzip # precompiled from /usr/lib/python2.5/gzip.pyc
import email # directory /usr/lib/python2.5/email
# /usr/lib/python2.5/email/__init__.pyc matches /usr/lib/python2.5/
email/__init__.py
import email # precompiled from /usr/lib/python2.5/email/__init__.pyc
import email.mime # directory /usr/lib/python2.5/email/mime
# /usr/lib/python2.5/email/mime/__init__.pyc matches /usr/lib/
python2.5/email/mime/__init__.py
import email.mime # precompiled from /usr/lib/python2.5/email/mime/
__init__.pyc
# /usr/lib/python2.5/email/encoders.pyc matches /usr/lib/python2.5/
email/encoders.py
import email.encoders # precompiled from /usr/lib/python2.5/email/
encoders.pyc
# /usr/lib/python2.5/quopri.pyc matches /usr/lib/python2.5/quopri.py
import quopri # precompiled from /usr/lib/python2.5/quopri.pyc
# /usr/lib/python2.5/email/mime/multipart.pyc matches /usr/lib/
python2.5/email/mime/multipart.py
import email.mime.mult ipart # precompiled from /usr/lib/python2.5/
email/mime/multipart.pyc
# /usr/lib/python2.5/email/mime/base.pyc matches /usr/lib/python2.5/
email/mime/base.py
import email.mime.base # precompiled from /usr/lib/python2.5/email/
mime/base.pyc
# /usr/lib/python2.5/email/message.pyc matches /usr/lib/python2.5/
email/message.py
import email.message # precompiled from /usr/lib/python2.5/email/
message.pyc
# /usr/lib/python2.5/uu.pyc matches /usr/lib/python2.5/uu.py
import uu # precompiled from /usr/lib/python2.5/uu.pyc
# /usr/lib/python2.5/email/charset.pyc matches /usr/lib/python2.5/
email/charset.py
import email.charset # precompiled from /usr/lib/python2.5/email/
charset.pyc
# /usr/lib/python2.5/email/base64mime.pyc matches /usr/lib/python2.5/
email/base64mime.py
import email.base64mim e # precompiled from /usr/lib/python2.5/email/
base64mime.pyc
# /usr/lib/python2.5/email/utils.pyc matches /usr/lib/python2.5/email/
utils.py
import email.utils # precompiled from /usr/lib/python2.5/email/
utils.pyc
# /usr/lib/python2.5/email/_parseaddr.pyc matches /usr/lib/python2.5/
email/_parseaddr.py
import email._parseadd r # precompiled from /usr/lib/python2.5/email/
_parseaddr.pyc
# /usr/lib/python2.5/email/quoprimime.pyc matches /usr/lib/python2.5/
email/quoprimime.py
import email.quoprimim e # precompiled from /usr/lib/python2.5/email/
quoprimime.pyc
# /usr/lib/python2.5/email/errors.pyc matches /usr/lib/python2.5/email/
errors.py
import email.errors # precompiled from /usr/lib/python2.5/email/
errors.pyc
# /usr/lib/python2.5/email/iterators.pyc matches /usr/lib/python2.5/
email/iterators.py
import email.iterators # precompiled from /usr/lib/python2.5/email/
iterators.pyc
# /usr/lib/python2.5/email/mime/text.pyc matches /usr/lib/python2.5/
email/mime/text.py
import email.mime.text # precompiled from /usr/lib/python2.5/email/
mime/text.pyc
# /usr/lib/python2.5/email/mime/nonmultipart.py c matches /usr/lib/
python2.5/email/mime/nonmultipart.py
import email.mime.nonm ultipart # precompiled from /usr/lib/python2.5/
email/mime/nonmultipart.py c
# /usr/lib/python2.5/unittest.pyc matches /usr/lib/python2.5/
unittest.py
import unittest # precompiled from /usr/lib/python2.5/unittest.pyc
# /usr/lib/python2.5/site-packages/apport/fileutils.pyc matches /usr/
lib/python2.5/site-packages/apport/fileutils.py
import apport.fileutil s # precompiled from /usr/lib/python2.5/site-
packages/apport/fileutils.pyc
# /usr/lib/python2.5/site-packages/apport/packaging_impl. pyc matches /
usr/lib/python2.5/site-packages/apport/packaging_impl. py
import apport.packagin g_impl # precompiled from /usr/lib/python2.5/
site-packages/apport/packaging_impl. pyc
import apt # directory /usr/lib/python2.5/site-packages/apt
# /usr/lib/python2.5/site-packages/apt/__init__.pyc matches /usr/lib/
python2.5/site-packages/apt/__init__.py
import apt # precompiled from /usr/lib/python2.5/site-packages/apt/
__init__.pyc
dlopen("/usr/lib/python2.5/site-packages/apt_pkg.so", 2);
import apt_pkg # dynamically loaded from /usr/lib/python2.5/site-
packages/apt_pkg.so
# /usr/lib/python2.5/site-packages/apt/package.pyc matches /usr/lib/
python2.5/site-packages/apt/package.py
import apt.package # precompiled from /usr/lib/python2.5/site-packages/
apt/package.pyc
# /usr/lib/python2.5/gettext.pyc matches /usr/lib/python2.5/gettext.py
import gettext # precompiled from /usr/lib/python2.5/gettext.pyc
# /usr/lib/python2.5/locale.pyc matches /usr/lib/python2.5/locale.py
import locale # precompiled from /usr/lib/python2.5/locale.pyc
dlopen("/usr/lib/python2.5/lib-dynload/_locale.so", 2);
import _locale # dynamically loaded from /usr/lib/python2.5/lib-
dynload/_locale.so
dlopen("/usr/lib/python2.5/lib-dynload/operator.so", 2);
import operator # dynamically loaded from /usr/lib/python2.5/lib-
dynload/operator.so
# /usr/lib/python2.5/site-packages/apt/cache.pyc matches /usr/lib/
python2.5/site-packages/apt/cache.py
import apt.cache # precompiled from /usr/lib/python2.5/site-packages/
apt/cache.pyc
# /usr/lib/python2.5/site-packages/apt/progress.pyc matches /usr/lib/
python2.5/site-packages/apt/progress.py
import apt.progress # precompiled from /usr/lib/python2.5/site-
packages/apt/progress.pyc
# /usr/lib/python2.5/site-packages/apt/cdrom.pyc matches /usr/lib/
python2.5/site-packages/apt/cdrom.py
import apt.cdrom # precompiled from /usr/lib/python2.5/site-packages/
apt/cdrom.pyc
# /usr/lib/python2.5/site-packages/apport/packaging.pyc matches /usr/
lib/python2.5/site-packages/apport/packaging.py
import apport.packagin g # precompiled from /usr/lib/python2.5/site-
packages/apport/packaging.pyc
# /usr/lib/python2.5/shutil.pyc matches /usr/lib/python2.5/shutil.py
import shutil # precompiled from /usr/lib/python2.5/shutil.pyc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'doerror' is not defined
>>xml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'xml' is not defined
>>import xml
xml.dom
<module 'xml.dom' from '/usr/lib/python2.5/xml/dom/__init__.pyc'>
>>import email
email.mime
<module 'email.mime' from '/usr/lib/python2.5/email/mime/
__init__.pyc'>
>>exit()
# clear __builtin__._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
# clear sys.exitfunc
# clear sys.exc_type
# clear sys.exc_value
# clear sys.exc_traceba ck
# clear sys.last_type
# clear sys.last_value
# clear sys.last_traceb ack
# clear sys.path_hooks
# clear sys.path_import er_cache
# clear sys.meta_path
# restore sys.stdin
# restore sys.stdout
# restore sys.stderr
# cleanup __main__
# cleanup[1] apport
# cleanup[1] zipimport
# cleanup[1] quopri
# cleanup[1] cStringIO
# cleanup[1] apport.report
# cleanup[1] math
# cleanup[1] exceptions
# cleanup[1] _locale
# cleanup[1] sre_constants
# cleanup[1] _codecs
# cleanup[1] pwd
# cleanup[1] _struct
# cleanup[1] _types
# cleanup[1] posix
# cleanup[1] site
# cleanup[1] problem_report
# cleanup[1] pyexpat
# cleanup[1] strop
# cleanup[1] grp
# cleanup[1] readline
# cleanup[1] sitecustomize
# cleanup[1] apport.packagin g
# cleanup[1] urlparse
# cleanup[1] gzip
# cleanup[1] signal
# cleanup[1] apport.packagin g_impl
# cleanup[1] zlib
# cleanup[1] apport.fileutil s
# cleanup[1] atexit
# cleanup[1] unittest
# cleanup[1] apport_python_h ook
# cleanup[1] shutil
# cleanup[1] glob
# cleanup[1] subprocess
# cleanup[1] gc
# cleanup[1] tempfile
# cleanup[1] thread
# cleanup[1] traceback
# cleanup[1] fnmatch
# cleanup[1] pickle
# cleanup[1] marshal
# cleanup[2] email.iterators
# cleanup[2] random
# cleanup[2] types
# cleanup[2] email.mime
# cleanup[2] xml
# cleanup[2] struct
# cleanup[2] base64
# cleanup[2] apt.cache
# cleanup[2] pyexpat.errors
# cleanup[2] apt_pkg
# cleanup[2] encodings.utf_8
# cleanup[2] email.quoprimim e
# cleanup[2] email.mime.text
# cleanup[2] email.encoders
# cleanup[2] pyexpat.model
# cleanup[2] locale
# cleanup[2] email.charset
# cleanup[2] xml.parsers.exp at
# cleanup[2] encodings
# cleanup[2] urllib
# cleanup[2] re
# cleanup[2] email.mime.base
# cleanup[2] email.errors
# cleanup[2] email
# cleanup[2] fcntl
# cleanup[2] apt.progress
# cleanup[2] UserDict
# cleanup[2] codecs
# cleanup[2] xml.dom.domreg
# cleanup[2] socket
# cleanup[2] xml.dom.xmlbuil der
# cleanup[2] os
# cleanup[2] _sre
# cleanup[2] xml.parsers
# cleanup[2] operator
# cleanup[2] select
# cleanup[2] posixpath
# cleanup[2] errno
# cleanup[2] _socket
# cleanup[2] binascii
# cleanup[2] email._parseadd r
# cleanup[2] os.path
# cleanup[2] apt.package
# cleanup[2] xml.dom.NodeFil ter
# cleanup[2] email.utils
# cleanup[2] copy
# cleanup[2] apt.cdrom
# cleanup[2] uu
# cleanup[2] xml.dom.minidom
# cleanup[2] apt
# cleanup[2] encodings.alias es
# cleanup[2] sre_parse
# cleanup[2] copy_reg
# cleanup[2] sre_compile
# cleanup[2] _random
# cleanup[2] email.message
# cleanup[2] string
# cleanup[2] email.mime.nonm ultipart
# cleanup[2] gettext
# cleanup[2] xml.dom.minicom pat
# cleanup[2] stat
# cleanup[2] _ssl
# cleanup[2] warnings
# cleanup[2] xml.dom
# cleanup[2] email.base64mim e
# cleanup[2] email.mime.mult ipart
# cleanup[2] linecache
# cleanup[2] time
# cleanup sys
# cleanup __builtin__
# cleanup ints: 58 unfreed ints in 7 out of 17 blocks
# cleanup floats: 33 unfreed floats in 2 out of 3 blocks
44,46c44
< >>be_nice = 100
< >>doerror
< import apport # directory /usr/lib/python2.5/site-packages/apport
---
>>import apport # directory /usr/lib/python2.5/site-packages/apport
217,218c215
< >>xml
< Traceback (most recent call last):
---
>Traceback (most recent call last):
221,228c218,220
< >>import xml
< >>xml.dom
< <module 'xml.dom' from '/usr/lib/python2.5/xml/dom/__init__.pyc'>
< >>import email
< >>email.mime
< <module 'email.mime' from '/usr/lib/python2.5/email/mime/
__init__.pyc'>
< >>exit()
< # clear __builtin__._
---
>><module 'xml.dom' from '/usr/lib/python2.5/xml/dom/__init__.pyc'>
<module 'email.mime' from '/usr/lib/python2.5/email/mime/__init__..pyc'>
# clear __builtin__._
DIFF TO RAW TRANSCRIPT

44,46c44
< >>be_nice = 100
< >>doerror
< import apport # directory /usr/lib/python2.5/site-packages/apport
---
>>import apport # directory /usr/lib/python2.5/site-packages/apport
217,218c215
< >>xml
< Traceback (most recent call last):
---
>Traceback (most recent call last):
221,228c218,220
< >>import xml
< >>xml.dom
< <module 'xml.dom' from '/usr/lib/python2.5/xml/dom/__init__.pyc'>
< >>import email
< >>email.mime
< <module 'email.mime' from '/usr/lib/python2.5/email/mime/
__init__.pyc'>
< >>exit()
< # clear __builtin__._
---
>><module 'xml.dom' from '/usr/lib/python2.5/xml/dom/__init__.pyc'>
<module 'email.mime' from '/usr/lib/python2.5/email/mime/__init__..pyc'>
# clear __builtin__._
Jul 27 '08 #5
Lie wrote:
Question: Is there a way to list loaded modules, including those that
aren't in my namespace?
such as sys.modules?

Modules are not unloaded automatically just because you do not use them
yourselves. If the module is imported for whatever reason by whatever other
module, it stays alive until it's no longer referenced (including the
reference in sys.modules).

Stefan
Jul 27 '08 #6
Lie
On Jul 27, 3:48*pm, Stefan Behnel <stefan...@behn el.dewrote:
Lie wrote:
Question: Is there a way to list loaded modules, including those that
aren't in my namespace?

such as sys.modules?

Modules are not unloaded automatically just because you do not use them
yourselves.
I'm not surprised of that.
If the module is imported for whatever reason by whatever other
module, it stays alive until it's no longer referenced (including the
reference in sys.modules).
I'm more concerned about the number of modules imported by making an
error (from 30 on the startup to 187) and the side-effect of making an
error, which makes modules such as xml.*/email.* that previously
doesn't exist get imported out of the blue... this makes the effect
that made me start the thread, a "command" that while getting
NameError in the first call, gets a modules found on subsequent call,
just because the Error Handler loaded it for you.

I'm even more concerned by a few modules that got imported because of
making the error, several of them isn't something that should be used
by Error Handler (e.g. email.*, apt (seems to be related to Ubuntu's
package manager of the same name), etc)

I'm also concerned in that why Error handling is on python's level
instead of built-in.

PS: These concerns are based on the assumption that the offender is
the "Error Handler", which I haven't proven completely, yet is the
strongest candidate on why this odd behavior comes to be.
Jul 27 '08 #7
Lie wrote:
I'm more concerned about the number of modules imported by making an
error (from 30 on the startup to 187) and the side-effect of making an
error, which makes modules such as xml.*/email.* that previously
doesn't exist get imported out of the blue...
Using my system Python (2.5.1 on Ubunutu Gutsy):

$ strace -e open python -c '' 2>&1 | wc -l
551
$ strace -e open python -c '<><<' 2>&1 | wc -l
4631

Using a self-built Python I have lying around:

$ strace -e open python2.3 -c '' 2>&1 | wc -l
210
$ strace -e open python2.3 -c '<><<' 2>&1 | wc -l
214

$ strace -e open python2.6 -c '' 2>&1 | wc -l
138
$ strace -e open python2.6 -c '<><<' 2>&1 | wc -l
142

Blame Ubuntu/Debian.

Stefan
Jul 27 '08 #8
Stefan Behnel <st*******@behn el.dewrote:
>Using my system Python (2.5.1 on Ubunutu Gutsy):

$ strace -e open python -c '' 2>&1 | wc -l
551
$ strace -e open python -c '<><<' 2>&1 | wc -l
4631

Using a self-built Python I have lying around:

$ strace -e open python2.3 -c '' 2>&1 | wc -l
210
$ strace -e open python2.3 -c '<><<' 2>&1 | wc -l
214

$ strace -e open python2.6 -c '' 2>&1 | wc -l
138
$ strace -e open python2.6 -c '<><<' 2>&1 | wc -l
142

Blame Ubuntu/Debian.
I'd be wary about including Debian in that blame. Using 4.0 here,
with a 2.4.4 default and a 2.5.0 straight from the package:

$ strace -e open python -c '' 2>&1 | wc -l
171
$ strace -e open python -c '<><<' 2>&1 | wc -l
175
$ strace -e open python2.5 -c '' 2>&1 | wc -l
105
$ strace -e open python2.5 -c '<><<' 2>&1 | wc -l
109

--
\S -- si***@chiark.gr eenend.org.uk -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
Jul 28 '08 #9
On 28 Jul, 16:15, Sion Arrowsmith <si...@chiark.g reenend.org.uk>
wrote:
Stefan Behnel <stefan...@behn el.dewrote:
Blame Ubuntu/Debian.

I'd be wary about including Debian in that blame. Using 4.0 here,
with a 2.4.4 default and a 2.5.0 straight from the package:
[...]

I can imagine that some of the Python Eggs magic could quite easily
inflate the number of files opened when doing imports. Information on
things like the state of site-packages, .pth files, the length of
PYTHONPATH and so on should surely accompany the numbers before
fingers are pointed.

Paul
Jul 28 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2177
by: Corne' Cornelius | last post by:
Hi, I'm experiencing some weirdness in a program, when subtracting 2 (double)'s which should result in 0, but instead it returns -1.11022e-16. It looks to me that changing the double x_step decleration to unsigned type, might help, but the compiler complains when i try that. Any ideas ? #include <iostream>
1
2434
by: (Pete Cresswell) | last post by:
TabControl on the right side of a form with two tabs: Tab #1 contains two subforms that show some dynamic query results. Tab #2 contains a ListView that gets dynamically populated as the user navigates a TreeView on the left side of the form. The first time I load the ListView, if the tab containing it is not selected (i.e. the ListView is not visible) the screen draws the ListView's contents in the upper left portion of the form -...
0
1559
by: Bruce B | last post by:
Hi group, I'm experiencing some extreme weirdness over the last week with IIS related to it's Mappings and how .NET is behaving. I can't explain the behavior as it seems very random. Our app has about 50 file extensions that we map in IIS and handle in our HTTPHandler to catch the reference and then lookup the correct content from a database. In addition, we do some magic in a HTTPModule to rewrite paths for file types we don't...
1
1288
by: VB Programmer | last post by:
My development machine has been working perfectly, writing ASP.NET apps, etc... I just went to open a project and it said: "Visual Studio .NET has detected that the specified web server is not running ASP.NET version 1.1. You will be unable to run ASP.NET Web apps or services." I reran "aspnet_regiis -i " but it still gives me the error. Here's the output:
5
2279
by: Phil Weber | last post by:
I'm attempting to debug an ASP.NET Web application in VS.NET 2003. I'm running the app and the debugger on my local machine (Windows XP Professional). I am logged in as a local administrator. In order to rule out permissions issues, I have set the processModel username to "SYSTEM" in my machine.config. Here's my problem: The ASP.NET app (compiled in debug mode) works correctly, whether I start it with debugging (F5) or without (Ctrl+F5)....
5
1706
by: David Thielen | last post by:
Hi; I am creating png files in my ASP .NET app. When I am running under Windows 2003/IIS 6, the file is not given the security permissions it should have. It does not have any permission for several users that the directory it is in has, including IUSR_JASMINE (my system is named jasmine). Here is the weird part. In my aps .net code I have the following: String jname = Request.PhysicalApplicationPath + "images\\java_" + fileNum +...
13
2370
by: Oliver Hauger | last post by:
Hello, In my html form I show a select-element and if this element is clicked I fill it per JavaScript/DOM with option-elements. I use the following code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>
1
1659
by: rhino | last post by:
I've got some positioning problems that I can't figure out. Can anyone help? My website was working fine in IE7 and the current releases of Firefox and Opera so I had a look at it in IE6 and found that it was messed up. The major problem is that in IE6 the index, which was supposed to be on the left, was on the right, OVERLAYING the content on its right side. I finally resolved that problem in a way that allows both versions of IE6 and...
2
2372
by: JYA | last post by:
Hi. I was writing an xmltv parser using python when I faced some weirdness that I couldn't explain. What I'm doing, is read an xml file, create another dom object and copy the element from one to the other. At no time do I ever modify the original dom object, yet it gets modified.
0
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9906
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9737
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8737
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.