Calling "def" functions from another file.

Terry Reedy tjreedy at udel.edu
Wed Aug 13 16:22:09 EDT 2008



frankrentef wrote:
> Newbie here....
> 
> I'm writing a Python program that has "def" functionality growing in
> leaps and bounds.  I'm a newbie to Python so be detailed.  Is there a
> way to create a py file with all the "def's" listed and just call them
> from the "program" py file?  How would I do this?  Say my "def" py
> file was named def.py and the program file was named "program.py"

This is what all the modules in the standard library are about.

func.py (in same directory as prog.py or in sys.path directory
----------------
def a(b,c):
   return b*c-(b+c)//2

prog.py
------------------
import func
print(func.a(2,4)) #3.0

# should print 5




More information about the Python-list mailing list