943,513 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 403
  • Python RSS
May 29th, 2009
0

Newbie With Function Trouble

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pydude94 is offline Offline
2 posts
since May 2009
May 29th, 2009
0

Re: Newbie With Function Trouble

Let me give you an example.
There are two files. The first is compute.py and has the code:
python Syntax (Toggle Plain Text)
  1. def sumup(a,b):
  2. return a+b

And there is your program, main.py
python Syntax (Toggle Plain Text)
  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.
Reputation Points: 56
Solved Threads: 65
Posting Whiz in Training
slate is offline Offline
242 posts
since Jun 2008
May 29th, 2009
0

Re: Newbie With Function Trouble

THX it helped.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pydude94 is offline Offline
2 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Web Spider Help
Next Thread in Python Forum Timeline: Parsing text from a SMI file and writing to a file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC