Python and ipython import

Hello,

I use openSuse 12.1 with Python 2.7.2, just the default that comes with the distribution.

When I do “from random import Random”, it works fine in ipython, but it fails in plain python as well in “#!/usr/bin/env python” scripts:

In [1]: from random import Random

In [2]:
In [1]: import random
In [2]: random.Random
Out[2]: random.Random
>>> from random import Random
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name Random

However I can import random module itself, but not the class:

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

sys.path in ipython:

'',
 '/usr/bin',
 '/usr/lib/python27.zip',
 '/usr/lib64/python2.7',
 '/usr/lib64/python2.7/plat-linux2',
 '/usr/lib64/python2.7/lib-tk',
 '/usr/lib64/python2.7/lib-old',
 '/usr/lib64/python2.7/lib-dynload',
 '/usr/lib64/python2.7/site-packages',
 '/usr/lib64/python2.7/site-packages/PIL',
 '/usr/local/lib64/python2.7/site-packages',
 '/usr/local/lib/python2.7/site-packages',
 '/usr/lib64/python2.7/site-packages/gtk-2.0',
 '/usr/lib/python2.7/site-packages',
 '/usr/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info',
 '/usr/lib/python2.7/site-packages/IPython/extensions']

sys.path in python:

'', 
 '/usr/lib/python27.zip', 
 '/usr/lib64/python2.7', 
 '/usr/lib64/python2.7/plat-linux2', 
 '/usr/lib64/python2.7/lib-tk', 
 '/usr/lib64/python2.7/lib-old', 
 '/usr/lib64/python2.7/lib-dynload', 
 '/usr/lib64/python2.7/site-packages', 
 '/usr/lib64/python2.7/site-packages/PIL', 
 '/usr/local/lib64/python2.7/site-packages', 
 '/usr/local/lib/python2.7/site-packages', 
 '/usr/lib64/python2.7/site-packages/gtk-2.0', 
 '/usr/lib/python2.7/site-packages', 
 '/usr/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']

random module is in /usr/lib64/python2.7/random.py, which is in both paths.

What the heck is going on? :slight_smile: .
Shall I fill a bugreport, or is this the expected behaviour? In Debian it works fine in plain Python, so I believe that I’m doing it correctly.

Hi,

I think you’d better ask this question in the development forum, you’ll have a bigger chance of getting an answer.

HTH

Lenwolf

#$!@%$#@# !!!
I had an empty random.py in the cwd.
Sorry for bothering you with with such a stupidity…