469,949 Members | 2,631 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,949 developers. It's quick & easy.

Calling "def" functions from another file.

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"

THNX
Aug 13 '08 #1
1 8681


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

Aug 13 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

40 posts views Thread by Steve Juranich | last post: by
5 posts views Thread by engsolnorm | last post: by
8 posts views Thread by Ulysse | last post: by
4 posts views Thread by Christian Joergensen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.