[Tutor] executing a function in a different file and class

Jeff Shannon jeff at ccvcorp.com
Fri Aug 20 21:34:18 CEST 2004


vicki at thepenguin.org wrote:
> Okay, I have written a logging function to allow me to pass a string and a
> mask to determine which places to log to. The LogMessage function is not
> contained within a class and looks like this:
>     [...]
> If I call this function from anywhere within a class in the same file, I
> can use it fine. I created a second file with a function defined in it,
> and I can't call the LogMessage function from there. 

You just need to import the file that LogMessage is in.

Say that LogMessage is in a file called MyLog.py.  Now, in another 
file that you want to use it in, you can simply do this:

import MyLog

# ....

Mylog.LogMessage("Foo!")

Hope that helps...

Jeff Shannon
Technician/Programmer
Credit International



More information about the Tutor mailing list