Results 1 to 3 of 3

Thread: Python and ipython import

  1. #1

    Default 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:
    Code:
    In [1]: from random import Random
    
    In [2]:
    Code:
    In [1]: import random
    In [2]: random.Random
    Out[2]: random.Random
    Code:
    >>> 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:
    Code:
    >>> 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:
    Code:
    ['',
     '/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:
    Code:
    ['', 
     '/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? .
    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.
    Last edited by tmoravec; 21-Dec-2011 at 06:09. Reason: Better formating

  2. #2

    Default Re: Python and ipython import

    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

  3. #3

    Default Re: Python and ipython import

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •