Mega Code Archive

 
Categories / Python / Language Basics
 

Import statement that imports names from a module directly

# Import statement that imports names from a module directly into the  # importing module's symbol table. #//File: fibo.py 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 from fibo import fib, fib2 fib(500) # There is even a variant to import all names that a module defines: from fibo import * fib(500) # This imports all names except those beginning with an underscore (_).