Module imports
tkpmep at hotmail.com
tkpmep at hotmail.com
Mon Jan 30 16:14:06 EST 2006
I have written a number of functions and stored them in a file named
myFunctions.py. This keeps all my functions under one roof, and if I
want to use or one or more of them in a program, I can start the
program off with
from myFunctions import f1,f2
Some of these functions require various math routines, so they in turn
have an import line
def f1(x,y):
from math import log
k = log(x)
I'd like to import all the math routines just once with a single import
at the top of myFunctions.py
and then rewrite all my functions to use this single import i.e.
import math
def f1(x,y):
k = math.log(x)
However, if I now import one of my functions into a program, i.e.
from myFunctions import f1,f2
f1 and f2 no longer have access the math functions they need. Is there
a way to make python automatically execute all the imports it finds at
the top of myFunctions.py so that all these system functions are
visible to the functions in myFunctions.py without having to import
them piecemeal?
Thomas Philips
More information about the Python-list
mailing list