[Tutor] calling user defined function

bob gailer bgailer at gmail.com
Sun Mar 15 15:00:02 CET 2009


roberto wrote:
> On Sun, Feb 22, 2009 at 11:10 PM, bob gailer <bgailer at gmail.com> wrote:
>   
>> roberto wrote:
>>     
>>> hello
>>> i have a question which i didn't solved yet:
>>> i can define a function using the text editor provided by IDLE 3.0;
>>> then i'd like to call this function from the python prompt
>>>
>>> but when i try to do it, python warns me that function doesn't exist
>>> of course if i define the function directly using the >>> prompt,
>>> after that everything is fine
>>>
>>> may you tell me where i have to save the file that defines the
>>> function is order to use it later ?
>>> is it a problem of path ?
>>>
>>>       
>> Let's say you saved the file as foo.py. Then:
>>     
>>>>> import foo
>>>>> foo.afunction()
>>>>>           
>
> thank you very much, the help you provided me works fine
>
> nonetheless, yesterday i met a little problem:
> the procedure you indicated me
>
>   
>>>>> import foo
>>>>> foo.afunction()
>>>>>           
>
> works fine but when i modify the function "afunction" in the file
> foo.py then no change occurs when i call it again, i mean the function
> behavior is exactely the same as before i made any modification; i
> tried to import foo again, but nothing happens, the output of
> "foo.afunction" is as if i never made any change to it ...
>
> if you have any suggestion, it is very appreciated
>   

After initially importing foo you must   reload(foo)   for changes to 
take effect.

-- 
Bob Gailer
Chapel Hill NC
919-636-4239


More information about the Tutor mailing list