Re: Functions continuing to ru after returning something?

2010-08-31 Thread Maxwell Hansen
On 08/30/2010 05:05 PM, Bradley Hintze wrote: I may be having a brain fart, but is it at all possible to have a function first return a value then continue its calculation. Like this simple example: my_var = 5 def my_function(): return my_var my_var +=1 This obviously won't work as

Re: Functions continuing to ru after returning something?

2010-08-31 Thread Peter Otten
Bradley Hintze wrote: I may be having a brain fart, but is it at all possible to have a function first return a value then continue its calculation. Like this simple example: my_var = 5 def my_function(): return my_var my_var +=1 This obviously won't work as written but is

Re: Functions continuing to ru after returning something?

2010-08-31 Thread Bruno Desthuilliers
Peter Otten a écrit : n = 1 def f(): ... global n ... try: ... return n ... finally: ... n += 1 ... The same without a global: def f(_n=[0]): try: return _n[0] finally: _n[0] += 1 But yeps, using a generator would be better. --

Re: Functions continuing to ru after returning something?

2010-08-31 Thread Paul Rubin
Bradley Hintze bradle...@aggiemail.usu.edu writes: my_var = 5 def my_function(): return my_var my_var +=1 def my_function(): temp = my_var my_var += 1 return temp -- http://mail.python.org/mailman/listinfo/python-list

Re: Functions continuing to ru after returning something?

2010-08-31 Thread Stefan Schwarzer
Hi, On 2010-08-31 02:05, Bradley Hintze wrote: I may be having a brain fart, but is it at all possible to have a function first return a value then continue its calculation. Like this simple example: my_var = 5 def my_function(): return my_var my_var +=1 This obviously won't

Functions continuing to ru after returning something?

2010-08-30 Thread Bradley Hintze
I may be having a brain fart, but is it at all possible to have a function first return a value then continue its calculation. Like this simple example: my_var = 5 def my_function(): return my_var my_var +=1 This obviously won't work as written but is there a cleaver way around this. --

Re: Functions continuing to ru after returning something?

2010-08-30 Thread MRAB
On 31/08/2010 01:05, Bradley Hintze wrote: I may be having a brain fart, but is it at all possible to have a function first return a value then continue its calculation. Like this simple example: my_var = 5 def my_function(): return my_var my_var +=1 This obviously won't work as

Re: Functions continuing to ru after returning something?

2010-08-30 Thread Aidan
Bradley Hintze wrote: I may be having a brain fart, but is it at all possible to have a function first return a value then continue its calculation. Like this simple example: my_var = 5 def my_function(): return my_var my_var +=1 This obviously won't work as written but is there a

Re: Functions continuing to ru after returning something?

2010-08-30 Thread Chris Rebert
On Mon, Aug 30, 2010 at 5:05 PM, Bradley Hintze bradle...@aggiemail.usu.edu wrote: I may be having a brain fart, but is it at all possible to have a function first return a value then continue its calculation. Like this simple example: my_var = 5 def my_function():    return my_var