Re: [Tutor] Calling a function does not return what I want it to return

2012-07-19 Thread Alexander Q.
On Thu, Jul 19, 2012 at 4:21 PM, Dave Angel wrote: > On 07/19/2012 06:58 PM, Alexander Q. wrote: > > I have this little program that is supposed to calculate how many > diagonals > > a polygon of x sides has, but it does not return what I have in the > > "return" part of the function when I call

Re: [Tutor] Calling a function does not return what I want it to return

2012-07-19 Thread Alan Gauld
On 20/07/12 00:17, Prasad, Ramit wrote: def num_diag(var): ans = 0 if var <= 3: print("No diagonals.") else: for i in range(num_sides - 3): ans = ans + i return (((var - 3)*2) + ans) num_sides = (int(raw_input("Enter sides: "))) num_diag(num_sides) NameError:

Re: [Tutor] Calling a function does not return what I want it to return

2012-07-19 Thread Dave Angel
On 07/19/2012 06:58 PM, Alexander Q. wrote: > I have this little program that is supposed to calculate how many diagonals > a polygon of x sides has, but it does not return what I have in the > "return" part of the function when I call it. Here is the code: > > def num_diag(var): > ans = 0 > if

Re: [Tutor] Calling a function does not return what I want it to return

2012-07-19 Thread Emile van Sebille
On 7/19/2012 3:58 PM Alexander Q. said... I have this little program that is supposed to calculate how many diagonals a polygon of x sides has, but it does not return what I have in the "return" part of the function when I call it. Here is the code: def num_diag(var): ans = 0 if var <= 3:

Re: [Tutor] Calling a function does not return what I want it to return

2012-07-19 Thread Prasad, Ramit
> I have this little program that is supposed to calculate how many diagonals a > polygon of x sides has, but it does not return what I have in the "return" > part of the function when I call it. Here is the code: > > def num_diag(var): > ans = 0 > if var <= 3: > print("No diagonals.") >

[Tutor] Calling a function does not return what I want it to return

2012-07-19 Thread Alexander Q.
I have this little program that is supposed to calculate how many diagonals a polygon of x sides has, but it does not return what I have in the "return" part of the function when I call it. Here is the code: def num_diag(var): ans = 0 if var <= 3: print("No diagonals.") else: for i i

Re: [Tutor] Calling a function within a function within a class...

2007-11-10 Thread Alan Gauld
"Trey Keown" <[EMAIL PROTECTED]> wrote > I'm creating a module for my program, and I need to call a function. > Here's how it's set up: > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- > class DoStuff: >def Thing1(self): >def ThingToCall(self): >print "It worke

Re: [Tutor] Calling a function within a function within a class...

2007-11-09 Thread Eric Brunson
Trey Keown wrote: > Hey all... > I'm creating a module for my program, and I need to call a function. > Here's how it's set up: > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- > class DoStuff: > def Thing1(self): > def ThingToCall(self): > print "It worked!" >

[Tutor] Calling a function within a function within a class...

2007-11-09 Thread Trey Keown
Hey all... I'm creating a module for my program, and I need to call a function. Here's how it's set up: -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- class DoStuff: def Thing1(self): def ThingToCall(self): print "It worked!" def Thing2(self): #Call

Re: [Tutor] Calling a function by string name

2006-07-21 Thread Smith, Jeff
nal Message-From: Michael P. Reilly [mailto:[EMAIL PROTECTED] Sent: Friday, July 21, 2006 1:36 PMTo: Smith, JeffCc: tutor@python.orgSubject: Re: [Tutor] Calling a function by string nameOn 7/21/06, Smith, Jeff <[EMAIL PROTECTED]> wrote: I have an object and

Re: [Tutor] Calling a function by string name

2006-07-21 Thread Michael P. Reilly
On 7/21/06, Smith, Jeff <[EMAIL PROTECTED]> wrote: I have an object and I want to call a method that I have constructed the name for in a string.   For example: str_method = 'myfun' obj.str_method   Of course, this fails.  I know I could probably do this with exec but is there a better

Re: [Tutor] Calling a function by string name

2006-07-21 Thread Kent Johnson
Smith, Jeff wrote: > I have an object and I want to call a method that I have constructed > the name for in a string. > > For example: > str_method = 'myfun' > obj.str_method > > Of course, this fails. I know I could probably do this with exec but > is there a better way? Use getattr(): get

[Tutor] Calling a function by string name

2006-07-21 Thread Smith, Jeff
Title: Message I have an object and I want to call a method that I have constructed the name for in a string.   For example: str_method = 'myfun' obj.str_method   Of course, this fails.  I know I could probably do this with exec but is there a better way?   For context, the specific appli

Re: [Tutor] Calling a function

2005-06-09 Thread Max Noel
On Jun 9, 2005, at 07:45, Kevin Reeder wrote: > I'm having trouble with this code which is meant to run a time > comparison between two similar functions. The first module is > makezeros.py > > def lots_of_appends(): > zeros = [] > for i in range(1): > zeros.append(0) > > def one_

Re: [Tutor] Calling a function

2005-06-09 Thread Joal Heagney
Kevin Reeder said: >def do_timing(num_times, *funcs): Took me a while to work out what went wrong, but the first part occurs here. The *funcs bit means that any extra arguments passed to do_timing will be put into a tuple called funcs. So do_timing(100, dosomething, dosomethingelse) will pass

Re: [Tutor] Calling a function

2005-06-09 Thread Kevin Reeder
Ewald & John, thanks for the help. i'll work on it some more with your ideas in mind (after getting some sleep). Kevin ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Calling a function

2005-06-09 Thread jfouhy
Quoting Kevin Reeder <[EMAIL PROTECTED]>: > The second module is timings.py. > > import time, makezeros > > def do_timing(num_times, *funcs): > totals = {} > for func in funcs: totals[func] = 0.0 > for x in range(num_times): > for func in funcs: >starttime = time.time() >

Re: [Tutor] Calling a function

2005-06-09 Thread Ewald Ertl
Hi! I don't know if I'm right here, because I've tested a simple model of what you're trying to do: on Wed, 8 Jun 2005 23:45:59 -0700 Kevin Reeder <[EMAIL PROTECTED]> wrote : - Kevin Reeder > import t

[Tutor] Calling a function

2005-06-08 Thread Kevin Reeder
I'm having trouble with this code which is meant to run a time comparison between two similar functions. The first module is makezeros.py def lots_of_appends(): zeros = [] for i in range(1): zeros.append(0) def one_multiply(): zeros = [0] * 10