Module directory

Alex Martelli aleaxit at yahoo.com
Mon Oct 18 05:17:44 EDT 2004


m <akhavan_mohsen at yahoo.com> wrote:

> Hello ,How are you I write a module as you see :
> 
> # Fibonacci numbers module
> def fib(n): # write Fibonacci series up to n
> a, b = 0, 1
> while b < n:
> print b,
> a, b = b, a+b
> def fib2(n): # return Fibonacci series up to n
> result = []
> a, b = 0, 1
> while b < n:
> result.append(b)
> a, b = b, a+b
> return result

Some mutant space-eating nanovirus has eaten all the leading whitespace
on each line.  Make sure you put the spaces back (and don't use tabs,
use real spaces).


> the tutorials tells me to insert this module in the current 
> directory I couldn't find the current directory ,where we should put 
> our modules?

How you find out the current directory depends on your platform.  For
example, in all Unix-like shells, the command to use for the purpose is
pwd.  If you are using a Python interactive session, either at a
commandline or via IDLE or other IDE, try os.getcwd -- e.g.:

>>> import os
>>> os.getcwd()
'/Users/alex/downloads/Python-2.4b1'
>>> 

If you don't tell us what platform you're using, we can't guess.

Alex



More information about the Python-list mailing list