The Famous Error Message: "ImportError: No module named python_script"

rich murphy RichardTRMurphy at yahoo.com
Thu Dec 14 15:13:42 EST 2006


Thanks to everyone who responded with valuable suggestions. I
appreciate them all. I found the exact reason why "import" command
fails.

At the beginning I created my script file with MS Notepad. After
studying all the advice, I realized that I did not try other text
editors just becuase the tutorial says: "use your favorite text editor
to create a file called fibo.py in the current directory with the
following contents:"

Then I created another file with the same stuff in it using WordPad.
The behaviour of the "import" command improved a lot but still not
good. Then I used MS-DOS' text editor to create the same file.
Immediately the "import" command worked as it was supposed to. Almost.
"fibo.fib2(100)" command stil does not work.


This is fine:
>>> fibo.fib(1000)
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987

This not fine:
>>> fibo.fib2(100)
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]


When I enter "fibo.fib2(100)", I get the following:

>>> fibo.fib2(100)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Python24\fibo.py", line 11, in fib2
    while b < n:
UnboundLocalError: local variable 'b' referenced before assignment


This is fine:
>>> fibo.__name__
'fibo'
>>> fib=fibo.fib
>>> fib(500)
1 1 2 3 5 8 13 21 34 55 89 144 233 377

Both Python2.4 and 2.5 are behaving the same. I will also try to create
the file with Vi editor.




More information about the Python-list mailing list