[Numpy-discussion] Crash on (un-orthodox) __import__

Andrea Gavana andrea.gavana at gmail.com
Tue Oct 4 06:04:48 EDT 2011


Hi All,

    I was fiddling here and there with some code doing dynamic import of
stuff, and I noticed that this code:

import os
import sys

init_name = r"C:\Python27\Lib\site-packages\numpy\__init__.py"

directory, module_name = os.path.split(init_name)
main = os.path.splitext(module_name)[0]

sys.path.insert(0, os.path.normpath(directory))

# Crash here...
mainmod = __import__(main)


Produces a hard crash on Python (i.e., a dialog box with a "python.exe has
stopped working" message). I know I am not supposed to import stuff like
that, but I was curious to understand why Python should crash in this way.
This happens on Python 2.7.2 with Numpy 1.6.1 and Python 2.5.4 with Numpy
1.5.0

Thank you for your suggestions :-D


Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

>>> import PyQt4.QtGui
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
ImportError: No module named PyQt4.QtGui
>>>
>>> import pygtk
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
ImportError: No module named pygtk
>>>
>>> import wx
>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20111004/84cb120a/attachment.html>


More information about the NumPy-Discussion mailing list