Connecting Tech Pros Worldwide Forums | Help | Site Map

Re: having a function in a separate file

Terry Reedy
Guest
 
Posts: n/a
#1: Oct 5 '08
Maryam Saeedi wrote:
Quote:
Hi all,
>
I have a very basic question. I was wondering if I can have a function
in a separate file
Yes, the separate file become a module.
Quote:
and in my main file sort of import that function and
Yes. either of

import somemod # and use somemod.func

from somemod import func # and use func
Quote:
if so are all the variables local
The function can access built-in objects and objects in the module it is
defined in. Otherwise, it has locals just as usual.
Quote:
and if I need any variables in the function I should give it as an input?
Yes.
Quote:
I need to call a function in many different tasks and I am improving
that function so I prefer to make the changes only once. If you have any
example I really appreciate it.
Look at Python coded files in the the standard library. Look in
..../Pythonx.y/Lib to find them.

tjr




Closed Thread