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

xml.dom's weirdness?

P: n/a
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
Share this Question
Share on Google+
9 Replies


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

P: n/a
Lie
On Jul 26, 2:29*pm, Fredrik Lundh <fred...@pythonware.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', 'MIMENonMultipart', 'MIMEText',
'Message', 'Parser', 'Utils', '_LOWERNAMES', '_MIMENAMES', '__all__',
'__builtins__', '__doc__', '__file__', '__name__', '__path__',
'__version__', '_name', 'base64MIME', 'email', 'importer',
'message_from_file', 'message_from_string', 'mime', 'quopriMIME',
'sys']
>>email.parser
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', 'MIMENonMultipart', '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_file', 'message_from_string', '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_XMLPLUS_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

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

P: n/a
Lie
On Jul 26, 6:03*pm, Fredrik Lundh <fred...@pythonware.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(modules)" (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_hook, warnings, linecache,
encodings (# directory /usr/lib/python2.5/encodings),
encodings (# precompiled from /usr/lib/python2.5/encodings/
__init__.pyc),
codecs, _codecs, encodings.aliases, 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.minicompat, xml.dom.minidom,
xml.dom.xmlbuilder, copy, xml.dom.NodeFilter,
xml.parsers (# directory /usr/lib/python2.5/xml/parsers),
xml.parsers (# precompiled from /usr/lib/python2.5/xml/parsers/
__init__.pyc),
xml.parsers.expat, 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.multipart,
email.mime.base, email.message, uu, email.charset,
email.base64mime, email.utils, email._parseaddr,
email.quoprimime, email.errors, email.iterators,
email.mime.text, email.mime.nonmultipart,
unittest, apport.fileutils, apport.packaging.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.packaging, 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.pyc matches /usr/lib/python2.5/
sitecustomize.py
import sitecustomize # precompiled from /usr/lib/python2.5/
sitecustomize.pyc
# /usr/lib/python2.5/site-packages/apport_python_hook.pyc matches /usr/
lib/python2.5/site-packages/apport_python_hook.py
import apport_python_hook # precompiled from /usr/lib/python2.5/site-
packages/apport_python_hook.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.aliases # 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.pyc matches /usr/lib/python2.5/
sre_constants.py
import sre_constants # precompiled from /usr/lib/python2.5/
sre_constants.pyc
# /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.minicompat # 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.xmlbuilder # 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.NodeFilter # 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.expat # 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.multipart # 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.base64mime # 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._parseaddr # 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.quoprimime # 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.pyc matches /usr/lib/
python2.5/email/mime/nonmultipart.py
import email.mime.nonmultipart # precompiled from /usr/lib/python2.5/
email/mime/nonmultipart.pyc
# /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.fileutils # 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.packaging_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.packaging # 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_traceback
# clear sys.last_type
# clear sys.last_value
# clear sys.last_traceback
# clear sys.path_hooks
# clear sys.path_importer_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.packaging
# cleanup[1] urlparse
# cleanup[1] gzip
# cleanup[1] signal
# cleanup[1] apport.packaging_impl
# cleanup[1] zlib
# cleanup[1] apport.fileutils
# cleanup[1] atexit
# cleanup[1] unittest
# cleanup[1] apport_python_hook
# 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.quoprimime
# cleanup[2] email.mime.text
# cleanup[2] email.encoders
# cleanup[2] pyexpat.model
# cleanup[2] locale
# cleanup[2] email.charset
# cleanup[2] xml.parsers.expat
# 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.xmlbuilder
# 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._parseaddr
# cleanup[2] os.path
# cleanup[2] apt.package
# cleanup[2] xml.dom.NodeFilter
# 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.aliases
# 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.nonmultipart
# cleanup[2] gettext
# cleanup[2] xml.dom.minicompat
# cleanup[2] stat
# cleanup[2] _ssl
# cleanup[2] warnings
# cleanup[2] xml.dom
# cleanup[2] email.base64mime
# cleanup[2] email.mime.multipart
# 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

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

P: n/a
Lie
On Jul 27, 3:48*pm, Stefan Behnel <stefan...@behnel.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

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

P: n/a
Stefan Behnel <st*******@behnel.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.greenend.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

P: n/a
On 28 Jul, 16:15, Sion Arrowsmith <si...@chiark.greenend.org.uk>
wrote:
Stefan Behnel <stefan...@behnel.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 discussion thread is closed

Replies have been disabled for this discussion.