Re: python package confusion

Discussion in 'Python' started by Dave Angel, Jul 23, 2012.

  1. Dave Angel

    Dave Angel Guest

    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
     
    Dave Angel, Jul 23, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Parvinder
    Replies:
    6
    Views:
    749
    Thomas G. Marshall
    Feb 27, 2005
  2. Jugdish
    Replies:
    3
    Views:
    339
    Scott David Daniels
    Jan 1, 2008
  3. Dale Amon

    import and package confusion

    Dale Amon, Apr 29, 2009, in forum: Python
    Replies:
    29
    Views:
    754
    Dennis Lee Bieber
    May 1, 2009
  4. Klein Stéphane
    Replies:
    3
    Views:
    595
    Steve Holden
    Dec 20, 2009
  5. Devin Jeanpierre

    Re: python package confusion

    Devin Jeanpierre, Jul 23, 2012, in forum: Python
    Replies:
    3
    Views:
    169
    Devin Jeanpierre
    Jul 24, 2012
Loading...

Share This Page