[Tutor] referencing external functions

A.T.Hofkamp a.t.hofkamp at tue.nl
Fri Nov 14 14:23:53 CET 2008


Robert Berman wrote:
> I have a number of functions written in a python script called script1.py. In 
> another  script, script2.py, I need to use a number of the functions residing in 
> script1.py. How do I make these functions known to script2.py.
> 
> Thank you,

script1.py:

def f(n):
   return n + 1



script2.py:

import script1

y = script1.f(3)


(I would suggest to use more meaningful names than scriptX.py)

Sincerely,
Albert


More information about the Tutor mailing list