Lets say I have a python model fibo.py
defined as below:
#Fibonacci numbers module
print "This is a statement"
def fib(n):
a,b = 0,1
while b < n:
print b
a, b = b, a+b
def fib2(n):
a,b = 0,1
result= []
while(b < n):
result.append(b)
a, b = b, a+b
return result
In my interpreter session, I do the following:
>> import fibo
This is a statement
>>> fibo.fib(10)
1
1
2
3
5
8
>>> fibo.fib2(10)
[1, 1, 2, 3, 5, 8]
>>> fibo.__name__
'fibo'
>>>
So far so good... restart the interpreter:
>>> from fibo import fib,fib2
This is a statement
>>> fibo.__name__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'fibo' is not defined
>>>
I expected the error as I have only imported fib
and fib2
. But I don't understand why the statement was printed when I only imported fib
and fib2
.
Secondly if I change the module as:
#Fibonacci numbers module
print "This is a statement"
print __name__
What should be the expected result?
yield b
: 1.for f in fib(n): print f
2.result = list(fib(n))