Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25845

Re: python package confusion

Date 2012-07-23 06:19 -0400
From Dave Angel <d@davea.name>
Subject Re: python package confusion
References <BsCdnb3NJ_bOvJDNnZ2dnUVZ7rmdnZ2d@bt.com>
Newsgroups comp.lang.python
Message-ID <mailman.2457.1343038791.4697.python-list@python.org> (permalink)

Show all headers | View raw


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@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@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

python package confusion Lipska the Kat <lipska@lipskathekat.com> - 2012-07-23 11:02 +0100
  Re: python package confusion Dave Angel <d@davea.name> - 2012-07-23 06:19 -0400
    Re: python package confusion Lipska the Kat <lipska@lipskathekat.com> - 2012-07-23 11:54 +0100
  Re: python package confusion Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-07-23 06:22 -0400
    Re: python package confusion Lipska the Kat <lipska@lipskathekat.com> - 2012-07-23 12:02 +0100
      Re: python package confusion David <bouncingcats@gmail.com> - 2012-07-23 21:16 +1000
        Re: python package confusion Lipska the Kat <lipska@lipskathekat.com> - 2012-07-23 12:43 +0100
    Re: python package confusion Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-24 05:38 +0000
      Re: python package confusion Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-07-24 03:49 -0400

csiph-web