python package confusion

Dave Angel d at davea.name
Mon Jul 23 12:19:26 CEST 2012


On 07/23/2012 06:02 AM, Lipska the Kat wrote:
> Hello again pythoners
>
> I'm trying to understand the python package stuff
>
> I have the following directory
>
> /home/lipska/python/dev/mods
>
> In this directory I have two files, both executable
>
> ----------------------
>
> #! /usr/bin/env python3.2
>
> # fibo.py Fibonacci numbers module
>
> def fib(n):    # write Fibonacci series up to n
>     a, b = 0, 1
>     while b < n:
>         print(b, end=' ')
>         a, b = b, a+b
>     print()
>
> ----------------------
>
> #! /usr/bin/env python3.2
>
> # test.py fibo module test program
>
> import fibo
>
> fibo.fib(1000)
>
> -----------------------
>
> The PYTHONPATH ev is set to /home/lipska/python/dev/mods:.
> in .bashrc
>
> The following interactive session works thusly
>
> lipska at ubuntu:~/python/dev/mods$ python3.2
> Python 3.2.3 (default, Jul 17 2012, 14:23:10)
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import fibo
> >>> fibo.fib(1000)
> 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
> >>>
>
> However if I try and run test.py as an executable I get the following
> error
>
> lipska at ubuntu:~/python/dev/mods$ test.py
> Traceback (most recent call last):
>   File "./test.py", line 5, in <module>
>     fib(1000)
> NameError: name 'fib' is not defined
>

That line isn't the way you showed it in the source.  You showed us
source as  fibo.fib(1000), and the error message shows it as fib(1000)

So you're either cutting & pasting wrong, or you have two test.py files.

-- 

DaveA




More information about the Python-list mailing list