Calling "def" functions from another file.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • frankrentef

    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
  • Terry Reedy

    #2
    Re: Calling "def&qu ot; functions from another file.



    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

    Comment

    Working...