Newbie With Function Trouble

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: May 2009
Posts: 2
Reputation: pydude94 is an unknown quantity at this point 
Solved Threads: 0
pydude94 pydude94 is offline Offline
Newbie Poster

Newbie With Function Trouble

 
0
  #1
May 29th, 2009
im a first time programmer learning python from books and so far ive learnt how to create and define functions but once ive saved them, im not sure how to call them so that i can use them. it works fine when i type in the function name but only if im in the same window that i wrote the function in. what i cant do is use IDLE to write the function, save it, and then call it in a completly new window. help, thx, toby.

oh and maybe i should mention im only 15, so if this is a really stupid question thats probably why.
Last edited by pydude94; May 29th, 2009 at 8:51 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 127
Reputation: slate is an unknown quantity at this point 
Solved Threads: 31
slate slate is offline Offline
Junior Poster

Re: Newbie With Function Trouble

 
0
  #2
May 29th, 2009
Let me give you an example.
There are two files. The first is compute.py and has the code:
  1. def sumup(a,b):
  2. return a+b

And there is your program, main.py
  1. import compute
  2. print compute.sumup(2,3)

The question is, how will python know where to find this compute module?

The answer is here.

So in the most simple case, if you put these two files into the same directory, you go there, and run python main.py , then it will work.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 2
Reputation: pydude94 is an unknown quantity at this point 
Solved Threads: 0
pydude94 pydude94 is offline Offline
Newbie Poster

Re: Newbie With Function Trouble

 
0
  #3
May 29th, 2009
THX it helped.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC